wp_get_attachment_image_attributes not working

I’ve replaced your string_replace call with preg_replace and converted your search string to proper regex (I use regex101 for that). Because you’re trying to replace images in the content, which wordpress saves as a string, you need to find anywhere in the content with an image and replace the src and srcset for it. This … Read more

Non-existent child page URLs redirects to the image attachment URL instead of throwing 404

If I understood you correctly you want to disable all attachment pages and redirect them to 404 page. Place this code in functions.php and try it again. add_action( ‘template_redirect’, ‘redirect_media_to_404’ ); function redirect_media_to_404() { if ( is_attachment() ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); get_template_part( 404 ); exit(); } }