WordPress filter hook · part of WordPress core
attachment_url_to_postid
A WordPress core filter that 6 plugins also fire themselves, running on 3M+ sites between them.
“This filter is documented in wp-includes/media.php”
How to use attachment_url_to_postid
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( 'attachment_url_to_postid', function( $id, $url ) {
// Change $id here.
return $id;
}, 10, 2 );Argument names come from Jetpack'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 →
6 plugins that fire attachment_url_to_postid
Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.
-
Jetpack3+ million installs
apply_filters( 'attachment_url_to_postid', $id, $url )jetpack_vendor/automattic/jetpack-podcast/src/feed/class-episode-media-cache.php:174 -
ThinkRank SEO20,000+ installs
apply_filters( 'attachment_url_to_postid', $attachment_id, $url )includes/seo/class-attachment-lookup.php:265 -
WPJAM Basic4,000+ installs
apply_filters( 'attachment_url_to_postid', $id, $url )public/wpjam-compat.php:901 -
WP Optimizer100+ installs
apply_filters( 'attachment_url_to_postid', null, $url )vendors/wps-framework/functions/images.php:104 -
WhereUsed90+ installs
apply_filters( 'attachment_url_to_postid', $post_id, $url )inc/Reference.php:235 -
Flexy SEOFewer than 10 installs
apply_filters( 'attachment_url_to_postid', null, $url )vendors/wps-framework/functions/images.php:104
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.