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 badge1 Answer
Reset to default 0Your 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条)