Insert Current URL into MailTo link in wordpress

I'm trying to figure out a simple way to "grab current URL" and use mailto link such as:

a href="mailto:email.com?subject=Booking%20Request%20%value%body=Hello%20Daisy%2C%0A%0AI'm%20interested%20in%20booking%20%value%%20for%202%20hours%20on%20this%20date%20%5Benter%20date%5D%20and%20this%20address%20%5Benter%20address%5D.%0A%0AI%20plan%20on%20doing%20the%20following%20activity%20%5Benter%20activity%5D.%0A%0ARegards%2C%0A%0A%5Benter%20your%20name%5D"Request Booking/a

The above is the mailto link I've created. I've stumbled upon the below to grab the URL:

global $wp;

$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );

My question is how do I incorporate the above URL grabbing code into usable html code? Or perhaps there is a plugin I can use that will inject the current URL into a contact form on another page after a user clicks 'book me'.

Grateful for any help offered as I've been scratching my head for the last couple days. My coding skills aren't that great - I'm newbie seeking to learn more.

Thank you

Topic plugins-url html-email Wordpress

Category Web


You are overkilling the idea of the query to get the url.

The simplest way and best way at the same time is:

<?php

    // get_the_ID() will return the current's post id
    // get_the_permalink() will return the current url
    $current_url = get_the_permalink(get_the_ID());

?>

That function will not echo, but rather return/get the permalink url for you. You can then incorporate the url by adding

...stuffbeforeurl<?php echo $current_url; ?>...stuffafterurl

into your link.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.