Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use post_comments_link filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
July 2, 2022
5 minutes read

post_comments_link filter

Filters the formatted post comments link HTML.

apply_filters( 'post_comments_link', string $formatted, int|WP_Post $post )


This hook is used for filters the HTML of a post comments link which can be get by get_post_reply_link() hook for a post.


  • $formatted : (string) The HTML-formatted post comments link.
  • $post : (int|WP_Post) The post ID or WP_Post object.

Live Example

To run the hook, copy the example below.

$formatted_link = apply_filters( 'post_comments_link', $formatted_link, $post ); 

if ( !empty( $formatted_link ) ) { 

// everything has led up to this point... 


The following example is for adding a hook callback.

// define the post_comments_link callback 
function filter_post_comments_link( $formatted_link, $post ) { 
// make filter magic happen here... 
return $formatted_link; 

// add the filter 
add_filter( 'post_comments_link', 'filter_post_comments_link', 10, 2 ); 

To remove a hook callback, use the example below.

// remove the filter 
remove_filter( 'post_comments_link', 'filter_post_comments_link', 10, 2 ); 




Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.