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

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742396811a4436113.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信