Wordpress - Encode text string being appended as query to URL
To encode the URL, you could use the PHP urlencode( $url )
function or use the WordPress urlencode_deep( $array | $str );
function.
add_shortcode( 'dynamic_contact_button', 'button_product_page' );
function button_product_page() {
global $product;
return urlencode( "/contact-form/?products=Product:%20" .$product->get_title(). "&#contact_form" );
}
links:
WordPress - urlencode_deep
urlencode
The urlencode()
function is your friend, it's a standard PHP function that encodes strings into URL valid format