Archived topic
Adding Post Comment Meta to Post Hero
3 replies · Started by Drew on June 19, 2019
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.
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 :)
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.
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.