嵌入变量作为 html link 的主题

embed variable as subject for a html link

我在 Wordpress 页面上有这样的 html 代码:

<a href="mailto:test@wb.nl?subject=taalfouten">test@wb.nl</a>

我想要实现的是在电子邮件主题中添加 page-title 或 url 作为变量。这可能吗?

第一组

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

例如在你的 header.php 文件中。

在您的页面模板中,您可以使用类似

的东西
<a href="mailto:test@test.com?subject=<?php echo $pagename; ?>">test@wb.nl</a>

试试这个,

<?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:test@wb.nl?subject='<?php echo $pagename ?>'">test@wb.nl</a>

这是为了显示页面标题,对我有用,同样适用于 URL

 $pageurl = $_SERVER['REQUEST_URI'];
 <a href="mailto:test@wb.nl?subject='<?php echo $pageurl ?>'">test@wb.nl</a>