Site logo

[Support request] calling to hook is not working

Home Forums Support [Support request] calling to hook is not working

Home Forums Support calling to hook is not working

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2477743
    Hung

    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.

    #2477760
    David
    Staff
    Customer Support

    Hi there,

    can you share a link to a post in your site where that code should appear ?

    #2477782
    Hung

    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.

    #2477868
    David
    Staff
    Customer Support

    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 ?

    #2477876
    Hung

    No. That’s why I want to find out the reason.

    #2477979
    David
    Staff
    Customer Support

    Does this work?

    add_action( 'generate_after_content', function(){
        echo 'hello world';
    });
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.