Firstly, I have done my research as thoroughly as I possibly can. Searches have been made, but I have not found any advice or solution as to my exact issue.
Ok, time to explain.
Currently I am working on a gallery theme for a client (I am not the original developer of this theme, it was created by another developer in the office). The theme is rather simple, the home page displays 220×170 thumbnails of each post containing an image. Click on the image, page with full size image comes up. Simple enough.
Now my trouble starts. The client would like to define which area of the image is displayed in the 220×170 thumbnail as currently WordPress just centers the image. My process to do this has been to upload the image to the gallery, insert into post and save.
I will then click on Set Featured image. The main problems begins here. There’s 2 ways I can go about this, both causing issues. If I crop the image, select Apply Changes to: Thumbnail, save it and then select Use as featured image, the featured image remains the full sized image, just resized to fit the 220×170 size.
At first I thought I figured out a solution, but I’d call it more of a band-aid fix and my client would rather avoid this next way. If I crop the image, instead now using All image sizes, this will now set the correctly cropped image as the thumnbnail, but will obviously overwrite … all the image sizes. So if I got back into my post (let’s say I accidentally deleted the image from the post) and I wanted to insert it back in, the image now inside of the gallery is the cropped image.
I’m trying to look for some guidance as to how I can fix the first issue, where the cropped thumbnail does not display in the featured image section, but rather just the full sized image.
Thank you,
It sounds as if your client is savvy enough with an image editing program.
Just thinking out loud here, but you could add a custom meta box and have the client upload 2 images. 1 – The smaller image that puts the focus where they want it 2 – The large image, to be used as the “Featured Image”.
Then call the custom image in the theme and the large image on click. I know it is an extra step for the client, but this is a method I have used in the past for a similar situation.
I have a solution for you. It is not perfect, but I have tested it for your needs, and it will work. There are a few “bugs” in WordPress, but I will discuss them later.
In you functions.php, define your images sizes:
That is just an example for your large image, here are some links in the WordPress Codex for more info:
In your theme, call the thumbnail with
Then for the large image, use
<?php the_post_thumbnail( 'very-large' ); ?>
Image”
to the post
Next, go to Admin >> Settings >> Media >> Thumbnail size. Enter 220 width and 170 height
Check “Crop thumbnail to exact dimensions (normally thumbnails are proportional)”
Here is one of the apparent bugs, I tested this 200+ different ways, I have set_post_thumbnail_size( 220, 220, true ); in the functions.php, but also needed to set the dimensions differently in the WordPress settings or vice versa
Now, in the post new post/edit post screen:
height, example: 225:171
image”
Here are more apparent bugs.
first drag a selection.
Wordpress thumbnail. You cannot enter the actual dimensions of the thumbnail.
for the thumbnail image, WordPress will not ALWAYS crop to 220×170
exactly. Through trial and error, I found that 225:171 always works.
Something else to watch out for, I found out, if the area selected is large and greatly disproportionately tall or wide, the thumbnail will not be displayed as exactly 220×170 either.
I suppose you could fudge a few pixels here or there by adding
height="170px"
andwidth="220px"
in the image code.I really hope someone more intelligent than me can come improve this method, but it is the best I could come up with after playing with it for two days.