admin管理员组

文章数量:1406974

I have a custom post type (events) and i made a custom template for archive and for single.

On single i want to add a shortcode to every post, this shortcode provides all dynamic data of the current post.

How can i input the shortcode in the_content() function?

I have a custom post type (events) and i made a custom template for archive and for single.

On single i want to add a shortcode to every post, this shortcode provides all dynamic data of the current post.

How can i input the shortcode in the_content() function?

Share Improve this question asked Oct 28, 2019 at 20:53 LovinQuaQuaLovinQuaQua 733 silver badges18 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can use the_content Hook: https://developer.wordpress/reference/hooks/the_content/

add_filter( 'the_content', 'my_shortchode_in_single_page' );
function my_shortchode_in_single_page($content){
    if(is_single())
        return $content . do_shortcode('YOUR SHORTCODE HERE');

    return $content;
}

本文标签: custom post typesAdd shortcode inside of thecontent()