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 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;

本文标签: functionsshortcode inside post called by ID does not render as expected