[Resolved] Missing generate_comment_link_output filter

Home Forums Support [Resolved] Missing generate_comment_link_output filter

Home Forums Support Missing generate_comment_link_output filter

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1143285
    Brooke.

    The generate_do_post_meta_item() function in inc/structure/post-meta.php seems to have a filter to modify the output for each post meta item except the comment link item. For example, if you look at the tag meta you’ll see:

    echo apply_filters( 'generate_tag_list_output',
    				sprintf( '<span...

    However, the comment link output looks like:

    if ( $comments && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
    			echo '<span class="comments-link">';...

    Can we add a generate_comment_link_output filter be added to a future version and is there a workaround for now?

    #1143873
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I wish it was possible, but WordPress (for some reason) doesn’t have a function to return the comments link – we can only echo it, which makes it impossible to filter.

    What about the output are you wanting to change?

    #1146047
    Brooke.

    Hi Tom,

    You’re right, I did some digging and it seems we are waiting on this trac ticket (or similar) to be addressed before it’s possible to return the comments_link.

    I’m actually overhauling the whole post meta area quite a bit. I think I may be able to accomplish some of this with CSS alone but editing the output of the comments would help quite a bit too. Since I’m already modifying the post date and category link (to return a custom taxonomy) I’m wondering if replacing the whole generate_do_post_meta_item function would make sense here but eager to hear your thoughts.

    #1146244
    Tom
    Lead Developer
    Lead Developer

    You can just add your own custom meta item:

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
        $items[] = 'custom-comments-link';
    
        return $items;
    } );
    
    add_action( 'generate_post_meta_items', function( $item ) {
        if ( 'custom-comments-link' === $item ) {
            // Your custom comments link in here.
        }
    } );

    Hope this helps ๐Ÿ™‚

    #1146338
    Brooke.

    Thanks Tom,

    That actually solved both the comments output as well as the hacky way I was previously outputting my custom taxonomy.

    #1146375
    Tom
    Lead Developer
    Lead Developer

    Awesome! Glad I could help ๐Ÿ™‚

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