[Resolved] adding a hook in entry-meta

Home Forums Support [Resolved] adding a hook in entry-meta

Home Forums Support adding a hook in entry-meta

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #751206
    Kemo

    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.

    View post on imgur.com

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

    Is there a hook for that?

    thanks a lot!

    #751523
    Leo
    Staff
    Customer Support

    Hi there,

    How are you adding the breadcrumbs?

    With a shortcode?

    #751721
    Kemo

    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

    #751748
    Leo
    Staff
    Customer Support

    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/

    #751799
    Kemo

    it works. thanks a lot, Leo!!

    #752205
    Leo
    Staff
    Customer Support

    No problem ๐Ÿ™‚

    #764037
    Junior Gong

    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

    #764273
    Kemo

    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

    #764275
    Tom
    Lead Developer
    Lead Developer

    Nice solution, Jacob! Thanks! ๐Ÿ™‚

    #764488
    Junior Gong

    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?

    #764830
    Tom
    Lead Developer
    Lead Developer

    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>

    #766341
    Junior Gong

    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?

    #766812
    Tom
    Lead Developer
    Lead Developer

    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' ) );
    } );
    #767190
    Junior Gong

    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

    #767891
    Tom
    Lead Developer
    Lead Developer

    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' ) );
    } );
Viewing 15 posts - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.