Home > Net >  Wordpress, filter/action before image renders?
Wordpress, filter/action before image renders?

Time:10-11

My task is to render watermarks on images, so I have to copy images and render the watermarks on them. The problem is, how to manage it from frontend? For example, I want to use the wp_get_attachment_image_src() function and a filter may change the source file URL. How to do that? This must be working: wp_get_attachment_url but then I dont know the ID of attachment so I cant make the thumbnail

CodePudding user response:

Try this filter

apply_filters( 'wp_get_attachment_image_src', array|false $image, int $attachment_id, string|int[] $size, bool $icon )

function alter_image_src($image, $attachment_id, $size, $icon)
{        
    $image[0] = 'http://example.com/test.jpg';

    return $image;
}
add_filter('wp_get_attachment_image_src', 'alter_image_src', 10, 4);
  • Related