WordPress filter hook · part of WordPress core

wp_count_attachments

A WordPress core filter that 2 plugins also fire themselves, running on 70K+ sites between them.

“Modify returned attachment counts by mime type.”

How to use wp_count_attachments

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:

functions.php
add_filter( 'wp_count_attachments', function( $value, $mime_type ) {
	// Change $value here.
	return $value;
}, 10, 2 );

Argument names come from Media Library Assistant'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 →

2 plugins that fire wp_count_attachments

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. Media Library Assistant icon Media Library Assistant70,000+ installs apply_filters( 'wp_count_attachments', (object) $counts, $mime_type ) includes/class-mla-list-table.php:167
  2. Post ID Optimizer icon Post ID Optimizer10+ installs apply_filters( 'wp_count_attachments', (object) $counts, $mime_type ) post-poidopt.php:2616

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.