Archived topic
calling to hook is not working
5 replies · Started by Hung on December 30, 2022
Hi.
I am trying a simple test in functions.php file.
add_action( 'generate_after_content', 'hp_related_posts' );
function hp_related_posts() {
global $post;
if ( is_single() ) {
$output = '<div class="related-posts">';
$output .= $post->ID;
$output .= '</div>';
}
return $output;
}
So, I assumed that before closing of the inside-article div, a new div, related-posts, will appear. However, nothing there when opening any post. Did I do something wrong? Please advice.
Thanks.
Hi there,
can you share a link to a post in your site where that code should appear ?
I am doing locally, so don't have an online link yet. But wondering if the above code is having something wrong? In the error server log, there is nothing recorded.
Right Click > Inspect the Post to open the browser developers tools, in the Elements tab, can you look for the HTML that is added by the function ?
No. That's why I want to find out the reason.
Does this work?
add_action( 'generate_after_content', function(){
echo 'hello world';
});
