php - How to call function at the bottom of post using plugin?

admin2025-06-03  5

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?

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?

Share Improve this question edited Feb 5, 2019 at 10:54 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Feb 5, 2019 at 10:00 Mangesh BarmateMangesh Barmate 212 bronze badges 1
  • Probably using a hook could be a working thing with the action the post : codex.wordpress/Plugin_API/Action_Reference/the_post – CRavon Commented Feb 5, 2019 at 10:11
Add a comment  | 

1 Answer 1

Reset to default 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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748941694a315015.html

最新回复(0)