Reputation: 55
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
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
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