Encode text string being appended as query to URL [closed]

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( "https://wordpress.stackexchange.com/contact-form/?products=Product:%20" .$product->get_title(). "&#contact_form" );
}

links:

WordPress – urlencode_deep

urlencode

Leave a Comment