WordPress users often find it infuriating to alter their images due to dimension limitations. For instance, after you upload an image that exceeds the allowed dimensions, WordPress will force you to crop it to fit it in the header frame. This often results in a severe drop in resolution, which may be unpleasant to some. I know it because I had witnessed this frustration firsthand and I needed to disable cropping in WordPress. Therefore, I skimmed the internet for a possible solution but to no avail; even WordPress’s official forum failed to provide me an answer. But, the solution came unexpectedly from a colleague of mine. Here’s what he offered.
Attention!By adjusting the source code, you are running the risk of crashing your website. We advise you to backup your data and approach with caution.
Time needed: 5 minutes.
- Go to your scripts
Dashboard > Appearance > Theme Editor.
- Locate the right script
The line of code you are looking for should include the maximum header dimensions.
- Replace the values…
…with the ones you desire.
- Save changes
Changing the Values in the PHP Script
WordPress themes crop images simply because they were programmed to do so. What’s more, each WP theme has a different line of code that changes the way images are uploaded. So, as you can imagine, modifying these snippets to your liking is not only possible but also necessary to remove limitations. In short, to bypass the mandatory cropping function, you first need to locate the line of code that triggers it. To get to the script, go to your dashboard and click on Appearance, then Theme Editor. The script might be anywhere under theme files, but possible files are functions.php, header.php, and custom-header.php.
The question is, how do you know when you locate the right piece of code? Simple. Just consider the dimensions specified as a maximum when you try to upload an image as a header. The line of code you are looking for should include these values.
Suppose your theme header supports a header that is 1000 pixels in width and 450 in height. In that case, you should skim for the values 1000 and 450, and once you find it, change the values with the exact dimension of the header image you wish to upload. For example, if you want to upload a 4000*2000 image (which we do not recommend for reasons we will reveal in upcoming posts), you need to change 1000 with 4000 and 450 with 2000. After that, hit save. This will update the maximum allowed dimensions to the ones you have set and disable cropping in WordPress.
'width' =>2560, #replace value with new width 'height'=>1440, #replace value with new height
Removing the Limitations
And there you have it. Although the frustration of not being able to upload an image the way you want is immeasurable, you can remove the limitations and structure your header the way you want with this simple trick. For more WordPress tips check out our other posts.