I want to have black and white thumbnail on page, and i want to show image in colour when mouse is on and when big image is shown (in lightbox)

I have this ->

function bw_images_size() {
    $crop = get_option('thumbnail_crop')==1 ? true : false;
    add_image_size('thumbnail-bw', get_option('thumbnail_size_w'), get_option('thumbnail_size_h'), $crop);

function bw_images_filter($meta) {
    $file = wp_upload_dir();
    $file = trailingslashit($file['path']).$meta['sizes']['thumbnail-bw']['file'];
    list($orig_w, $orig_h, $orig_type) = @getimagesize($file);
    $image = wp_load_image($file);
    imagefilter($image, IMG_FILTER_GRAYSCALE);
    //imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
    switch ($orig_type) {
        case IMAGETYPE_GIF:
            $file = str_replace(".gif", "-bw.gif", $file);
            imagegif( $image, $file );
        case IMAGETYPE_PNG:
            $file = str_replace(".png", "-bw.png", $file);
            imagepng( $image, $file );
        case IMAGETYPE_JPEG:
            $file = str_replace(".jpg", "-bw.jpg", $file);
            imagejpeg( $image, $file );
    return $meta;

And i have 4 image in 3 size (1024x628, 150x100, 300x200) and 1 "name-150x100-bw.jpg".

But i don't know how to use this bw.jpg. Above code is from http://bavotasan.com/2011/create-black-white-thumbnail-wordpress but code to get in loop worked only for featured image in post.

Thank you.


1 Answer 1


I think the best way to do this would be to add a filter to when the content is pulled into the post/page:

<?php add_filter( 'the_content', 'add_bw_thumbnails' ) ?>

Or to when an image is inserted into the editor:

add_filter( 'post_thumbnail_html', 'add_bw_thumbnails', 10 );
add_filter( 'image_send_to_editor', 'add_bw_thumbnails', 10 );

You then just have to write the function to do the replacement. Do you want to do this for all pages, or only those in a gallery, and are you sure 150x150 is the right thumbnail size?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.