Did you ever wonder if there was a way to automatically grayscale images in WordPress when you upload them? Well the wondering time is over. In this article, we will show you how you can use some simple PHP image manipulation tools and WordPress functions to automatically grayscale images upon upload. You can use grayscale images for hover, sliders, gallery, or anything else you like.
First thing you need to do is open your theme’s functions.php file and add the following code:
Tables can't be imported directly. Please insert an image of your table which can be found here.
1 2 3 4
The code above simply adds an additional image size for the uploader. The size is set to 100 x 100px with hard cropping. You may change the dimensions to fit your needs. Once you have done that, you need to add the following code:
Tables can't be imported directly. Please insert an image of your table which can be found here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
The code above pretty much tells the uploader to create an extra size of the image you uploaded. Crop it to the size you have specified in the previous step. Then apply the image filter: Grayscale.
If you were doing this for your post thumbnails, then you can display it like this in your theme:
Tables can't be imported directly. Please insert an image of your table which can be found here.
1
If you want to do this for a specific attachment, then you can use wp_get_attachment_image function.
Note: You should change themename to your theme’s name.