Site logo

Archived topic

adding a hook in entry-meta

22 replies · Started by Kemo on December 7, 2018

Viewing posts 1–15 of 23

I would like to move my breadcrumbs NavXT which I'm displaying above the post title, to inside the entry-meta - at the end of it.

https://imgur.com/a/viNVOQH

So that it would say December 5th by Jane Summers filed in Health > Fitness > Yoga

Is there a hook for that?

thanks a lot!

Hi there,

How are you adding the breadcrumbs?

With a shortcode?

I'm using elements(hook):


<?php if ( function_exists( 'bcn_display' ) && ! is_front_page() ) : ?>
    <div class="breadcrumbs">
        <?php bcn_display(); ?>
    </div>
<?php endif; ?>

hook:before_entry_title

thanks

Can you try this snippet here?

add_filter( 'generate_post_author_output', 'lh_breadcrumb_to_author' );
function lh_breadcrumb_to_author( $output ) {
  
  echo $output . ' - ';
  
  if ( function_exists( 'bcn_display' ) && ! is_front_page() ) {
    echo '<div class="breadcrumbs">';
        bcn_display();
    echo '</div>';
  }
}

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

it works. thanks a lot, Leo!!

No problem :)

I would like to add the number of comments at the end of the the entry-meta div. How can I achieve that?

Currently I am using an element to display content with the hook after_entry_title

An actual hook at the end of entry-meta div would be great long term since it seems like an often customized piece of information

There's no hook for that but similar to what Leo did:

to add "something" at the end of meta:


add_filter( 'generate_post_author_output', 'add_to_end_of_meta' );
function add_to_end_of_meta( $output ) {
  
  echo $output . ' something';
  
}

add this to your functions.php of your child theme

or number of comments:


add_filter( 'generate_post_author_output', 'add_to_end_of_meta' );
function add_to_end_of_meta( $output ) {
  
  echo $output . comments_number( 'no responses', 'one response', '% responses' );
  
}

source: https://codex.wordpress.org/Function_Reference/comments_number

let me know if it works. cheers

Nice solution, Jacob! Thanks! :)

That's a great solution!

Two things:

1. Now it reads 'x comments by author' since it is appended the comment count before the author's name. My original goal was to add it after the author's name though.

Is there any way to put the number of comments after the author's name?

2. How can I add a comment icon <i class="fa fa-comments-o"></i> before the comment count?

Try this instead:

add_filter( 'generate_post_author_output', function( $output ) {
    $comment_text = '<span class="comments-number">' . get_comments_number_text( 'No comments', '1 comment', '% comments' ) . '</span>';

  echo $output . $comment_text;
} );

To add an icon, you'd need to add Font Awesome to the site: https://wordpress.org/plugins/font-awesome/

Then you could replace this:

<span class="comments-number">

With this:

<span class="comments-number"><i class="far fa-comments"></i>

hey Tom

thx for the input. From the old hooks guide I still have this code:


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();
}

How can I combine the snippet you mentioned above with the comments_popup_link function?

You could try this:

add_filter( 'generate_post_author_output', function( $output ) {
    echo $output;
    comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
} );

Thx Tom, that works. Now I only want to add the FA comments icon and add a | in front of it so it looks like:

[date] by [author] | <i class="fa fa-comments-o"></i> 100 Comments

In that case, you would do this:

add_filter( 'generate_post_author_output', function( $output ) {
    echo $output . ' | <i class="fa fa-comments-o"></i>';
    comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
} );
This archived topic is closed to new replies.