Change the URL of an image from wp_get_attachment_image_src except in the frontpage
-
26-04-2021 - |
Question
This is the code I used that is working, but I want it to work only on product posts and not on the frontpage.
function alterImageSRC($image, $attachment_id, $size, $icon){
$image[0] = 'http://newimagesrc.com/myimage.jpg';
return $image;
}
add_filter('wp_get_attachment_image_src', 'alterImageSRC', 10, 4);
Solution
This code worked for me:
function alterImageSRC($image, $attachment_id, $size, $icon){
if ( is_front_page() ) {
return $image;
}
$image[0] = 'http://newimagesrc.com/myimage.jpg';
return $image;
}
add_filter('wp_get_attachment_image_src', 'alterImageSRC', 10, 4);
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange