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

functions - shortcode inside post called by ID does not render as expected

programmeradmin5浏览0评论

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 badge
Add a comment  | 

1 Answer 1

Reset to default 2

See 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;
发布评论

评论列表(0)

  1. 暂无评论