Marcel
Marcel

Reputation: 55

embed variable as subject for a html link

I have a html code like this on a Wordpress page:

<a href="mailto:[email protected]?subject=taalfouten">[email protected]</a>

What I want to achieve is to add the page-title or url as a variable in the email subject. Is that at all possible?

Upvotes: 0

Views: 154

Answers (2)

a.prakash
a.prakash

Reputation: 151

Try this,

<?php 
 $pagename = get_query_var('pagename');  
   // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object

   if ( !$pagename && $id > 0 ) {  
    $post = $wp_query->get_queried_object();  
    $pagename = $post->post_name;  
 } ?>

 <a href="mailto:[email protected]?subject='<?php echo $pagename ?>'">[email protected]</a>

this is for displaying page title which is worked for me, Similarly for URL

 $pageurl = $_SERVER['REQUEST_URI'];
 <a href="mailto:[email protected]?subject='<?php echo $pageurl ?>'">[email protected]</a>

Upvotes: 1

f.overflow
f.overflow

Reputation: 298

First set

<?php $pagename = get_query_var('pagename'); ?>

e.g. in your header.php file.

In your template for your page you can use something like

<a href="mailto:[email protected]?subject=<?php echo $pagename; ?>">[email protected]</a>

Upvotes: 1

Related Questions