最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Current WordPress Page Title as Search Parameter into A Tag <a href=“www.domain.coms?=currentpagetitle”>&

programmeradmin0浏览0评论

i would like to include an affiliate link as a widget which inserts the title of the respective page as search parameter.

<a href="www.amazon/s?=titleofthepage">Link</a>

I have already created a shortcode in the functions.php with get_the_title

function post_title_shortcode(){
$variable = get_the_title();
}
add_shortcode('post_title','post_title_shortcode'); 

and it is called [post_title]

However

<a href="www.amazon.de/s?=[post_title]"></a>

didn't work. Does anyone have any other idea how to make this happen?

i would like to include an affiliate link as a widget which inserts the title of the respective page as search parameter.

<a href="www.amazon/s?=titleofthepage">Link</a>

I have already created a shortcode in the functions.php with get_the_title

function post_title_shortcode(){
$variable = get_the_title();
}
add_shortcode('post_title','post_title_shortcode'); 

and it is called [post_title]

However

<a href="www.amazon.de/s?=[post_title]"></a>

didn't work. Does anyone have any other idea how to make this happen?

Share Improve this question asked May 27, 2020 at 11:26 Julian FleischerJulian Fleischer 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Your shortcode is getting the title, but you haven't told it to return anything, so a small tweak should fix things:

<?php
function post_title_shortcode(){
    return get_the_title();
}
add_shortcode('post_title','post_title_shortcode');
?>

You could also continue setting get_the_title() to $variable and add a line to return $variable, but the above is the simplest, shortest option.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论