[Support request] Adding Post Comment Meta to Post Hero

Home Forums Support [Support request] Adding Post Comment Meta to Post Hero

Home Forums Support Adding Post Comment Meta to Post Hero

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #935081
    Drew

    Hello,

    I’m looking to add a post comments link displaying the number of comments on the post hero. I’m having a tough time finding the right template tag for elements.

    #935089
    Leo
    Staff
    Customer Support

    Hi there,

    Add this PHP snippet to create a shortcode:

    add_shortcode( 'comment_number', 'tu_comment_number_sc' );
    function tu_comment_number_sc() {
        ob_start();
        comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
        return ob_get_clean();
    }

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Then you can use [comment_number] inside page hero content.

    Let me know if this helps 🙂

    #1634355
    Raul

    Why it’s not possible to add this code as a hook? Because hooks also works with php but this code works only in functions.php.

    #1634408
    David
    Staff
    Customer Support

    Hi there,

    If you’re using a Header Element the only way to display Dynamic Content is to use a Short Code. As we DO NOT allow PHP editing in the Header Element for security reasons. And there are no hooks inside the header element.

    If you’re using a Hook Element then by all means you can simply write your PHP code in the hook.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.