WordPress filter hook · part of WordPress core
comments_array
A WordPress core filter that 8 plugins also fire themselves, running on 64K+ sites between them.
“Filters the comments array.”
How to use comments_array
It's a filter: your callback receives the value and 1 more argument, and must return the (changed) value.
Add this to your theme's functions.php or a small custom plugin:
add_filter( 'comments_array', function( $comments_flat, $ID ) {
// Change $comments_flat here.
return $comments_flat;
}, 10, 2 );Argument names come from Tasty Recipes Lite's source. Other plugins may pass different values: check the call in the plugin you're targeting below.
This hook is fired by WordPress core too. Official reference on developer.wordpress.org →
8 plugins that fire comments_array
Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.
-
Comments60,000+ installs
apply_filters( 'comments_array', $commentList, $this->commentsArgs["post_id"] )class.WpdiscuzCore.php:1187 -
Tasty Recipes Lite2,000+ installs
apply_filters( 'comments_array', $comments_flat, $post->ID )inc/class-distribution-metadata.php:1324 -
Nova Blocks by Pixelgrade800+ installs
apply_filters( 'comments_array', $comments_flat, $query_args['post_id'] )build/block-library/blocks/post-comments/lib/renderers/class-novablocks-comments-list.php:329 -
AMP WP600+ installs
apply_filters( 'comments_array', $comments->comments, $post_id )includes/functions/amp-wp-theme-functions.php:2544 -
Visual Builder200+ installs
apply_filters( 'comments_array', $comments_flat, $post->ID )inc/comments-template.php:120 -
Ultimate AMP10+ installs
apply_filters( 'comments_array', $comments->comments, $post_id )inc/class-uamp-helper.php:87 -
Image Gallery and comments10+ installs
apply_filters( 'comments_array', $comments, $post->ID )ajax/commentshow.php:51 -
LH Comment Form Shortcode and BlockFewer than 10 installs
apply_filters( 'comments_array', $comments_flat, $post->ID )lh-comment-form-shortcode.php:325
Need a customisation built on this hook?
Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.