admin管理员组文章数量:1410705
Hallo i get a post in the theme like this:
$footer_post = get_post(pll_get_post(620));
echo $footer_post->post_content; // Load contents of the page
That shows the content of post(620) in the footer.
in the functions.php i have:
function year_shortcode() {
$year = date('Y');
return $year;}
add_shortcode('YEAR', 'year_shortcode');
The problem is, when i write [YEAR] and try to use the shorcode in that specific post, it will render like [YEAR] instead of 2019. Is this a bug or do i have to make a change to my code? When i use the shortcode in a normal site, it renders properly.
WordPress 5.2.4 latest.
Hallo i get a post in the theme like this:
$footer_post = get_post(pll_get_post(620));
echo $footer_post->post_content; // Load contents of the page
That shows the content of post(620) in the footer.
in the functions.php i have:
function year_shortcode() {
$year = date('Y');
return $year;}
add_shortcode('YEAR', 'year_shortcode');
The problem is, when i write [YEAR] and try to use the shorcode in that specific post, it will render like [YEAR] instead of 2019. Is this a bug or do i have to make a change to my code? When i use the shortcode in a normal site, it renders properly.
WordPress 5.2.4 latest.
Share Improve this question asked Nov 6, 2019 at 22:25 taxishoptaxishop 11 bronze badge1 Answer
Reset to default 2See this answer: How to get shortcode to work inside a foreach loop called within a shortcode?
You'll likely want apply_filters( 'the_content', $footer_post->post_content )
And so, in your case:
$footer_content = apply_filters( 'the_content', $footer_post->post_content );
echo $footer_content;
本文标签: functionsshortcode inside post called by ID does not render as expected
版权声明:本文标题:functions - shortcode inside post called by ID does not render as expected 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745024346a2638319.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论