admin管理员组文章数量:1428870
I am trying to create a shortcode from a custom function in WP but it seems like I'm doing something wrong.
I have a function in child's theme function.php and add_shortcode code:
function uniquetestfunction() {
echo '<div class="my_class">Test Element</div>';
}
add_shortcode(‘uniqueshortcodename’,’uniquetestfunction’);
Which should generate a shortcode [uniqueshortcodename]. I have done this with existing functions in different plugins and it worked fine.
But when added to a page, it's not rendering the function, just showing the shortcode as a text. Any ideas what I'm doing wrong?
I'm very new to PHP :) Thanks
I am trying to create a shortcode from a custom function in WP but it seems like I'm doing something wrong.
I have a function in child's theme function.php and add_shortcode code:
function uniquetestfunction() {
echo '<div class="my_class">Test Element</div>';
}
add_shortcode(‘uniqueshortcodename’,’uniquetestfunction’);
Which should generate a shortcode [uniqueshortcodename]. I have done this with existing functions in different plugins and it worked fine.
But when added to a page, it's not rendering the function, just showing the shortcode as a text. Any ideas what I'm doing wrong?
I'm very new to PHP :) Thanks
Share Improve this question asked May 1, 2019 at 13:48 jade newportjade newport 251 silver badge5 bronze badges1 Answer
Reset to default 2If you refer to the documentation for add_shortcode, you need your function to return the content:
function uniquetestfunction($attributes) {
return '<div class="my_class">Test Element</div>';
}
add_shortcode('uniqueshortcodename','uniquetestfunction');
You also used the wrong quotes in your add_shortcode line - stick with single '
or double "
quotes.
本文标签: phpShortcode from a function not working
版权声明:本文标题:php - Shortcode from a function not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745535171a2662238.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论