Proper way to hook wp_get_attachment_url or any other way to change that url in media library

The filter has 2 parameters, also the function name doesn’t match. So your code should look like this:

add_filter('wp_get_attachment_url', 'clrs_get_attachment_url', 10, 2);

function clrs_get_attachment_url($url, $post_id) {
   // Do what you want to $url
   return $url;
}

Leave a Comment