WordPress filter hook · part of WordPress core
wp_get_attachment_url
A WordPress core filter that 11 plugins also fire themselves, running on 14M+ sites between them.
“Filter the attachment URL.”
How to use wp_get_attachment_url
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( 'wp_get_attachment_url', function( $src, $post_id ) {
// Change $src here.
return $src;
}, 10, 2 );Argument names come from Yoast SEO'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 →
11 plugins that fire wp_get_attachment_url
Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.
-
Yoast SEO10+ million installs
apply_filters( 'wp_get_attachment_url', $src, $post_id )inc/sitemaps/class-sitemap-image-parser.php:407 -
Rank Math SEO4+ million installs
apply_filters( 'wp_get_attachment_url', $src, $post_id )includes/modules/sitemap/class-image-parser.php:406 -
SOOZ2,000+ installs
apply_filters( 'wp_get_attachment_url', $canonical_url, $post_id )includes/core/attachments-media.php:1244 -
MaxGalleria1,000+ installs
apply_filters( 'wp_get_attachment_url', $url, $attachment->ID )maxgalleria.php:1139 -
ARI Stream Quiz1,000+ installs
apply_filters( 'wp_get_attachment_url', $url, $post->post_id )libraries/arisoft/core/wordpress/class-helper.php:135 -
Images via imgix70+ installs
apply_filters( 'wp_get_attachment_url', $image_src )includes/class-images-via-imgix.php:190 -
LTI Sitemap10+ installs
apply_filters( 'wp_get_attachment_url', $url, $post->ID )src/generators/sitemap.php:333 -
Post ID Optimizer10+ installs
apply_filters( 'wp_get_attachment_url', $url, $post->ID )post-poidopt.php:5654 -
CloudSync Master10+ installs
apply_filters( 'wp_get_attachment_url', $localUrl, 0 )includes/WP/CloudSyncMaster/Admin/Table/ColumnTypeBuilder/ObjectLinkBuilder.php:140 -
Rooster LMSFewer than 10 installs
apply_filters( 'wp_get_attachment_url', $full, $id )includes/Events/EventPosts.php:135 -
AgenticCartFewer than 10 installs
apply_filters( 'wp_get_attachment_url', $attachment_url, (int) $att->ID )classes/sync/class-agentic-bulk-processor.php:575
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.