Site logo

Archived topic

Missing generate_comment_link_output filter

5 replies · Started by Brooke. on January 24, 2020

Viewing posts 1–6 of 6

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?

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?

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.

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 :)

Thanks Tom,

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

Awesome! Glad I could help :)

This archived topic is closed to new replies.