1

I am creating a plugin and need to write a function which will invoke at the bottom of posts.

Currently, I have a shortcode created and I'm calling the shortcode at bottom of each post wherever required. I need to add the created shortcode function in the plugin now and invoke from there.

Can anyone suggest me action type to invoke the created function at the bottom of the posts?

1

1 Answer 1

2

If you currently are using shortcodes, then most probably you want to display some dynamic content at the bottom of the post. If so, then there is a hook that will allow you to do that: the_content

If you want to modify the content only when single post is displayed, then you can use this code:

function my_the_content_filter( $content ) {
    if ( is_single() && get_the_ID() === get_queried_object_id() ) {
        $content .= '<div>Some additional content or whatever you want to be printed in here...</div>';
    }

    return $content;
}
add_filter( 'the_content', 'my_the_content_filter' );

If you want to modify it everywhere, then you should change the condition to match your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.