Is there a way to turn off automatic -widthxheight being added to my WordPress image URL? Like, for example;
http://xevens.com/projects/xe/wp-content/uploads/2014/10/alaska_winter_nights-1366×768-300×168.jpg
http://xevens.com/projects/xe/wp-content/uploads/2014/10/alaska_winter_nights-1366×768.jpg
That 300×168 is unnecessary to me in most cases. And now I need the image to be its original dimensions. If there’s no way to do that, can you at least brew me a nice little REGEX so I can get rid of -300×168 via jQuery?
Thanks!
You can use a simple regex like this:
Working demo
You can replace the matched content with a
.
as you can see in the screenshotI can think of a few regex variations depending on the situation with the WordPress images.
1
If you want a regex which selects only the image name from resized images in the wp-content/uploads and EXCLUDES the resized portion, you could do something more specific:
Working Demo
Group $1 selects the file name (excluding the resized part) and group $2 selects the extension
2
Or, if you were moving your library and wanted to change the URL even for non-resized images, but still need to exclude the resized portion of the filename: Working Demo
Group $1 selects the file name (excluding the resized part), group $2 selects the extension, and group $3 selects entire filenames for those files that don’t have a resize. If you output $1$2$3 it will either combine $1 and $2, or show $3 – so you always get the filename without the resized portion.
3
Or if you want to select only the resized portion of the filename for any of the image uploads: Working Demo
Group $1 selects the resized portion of the files that are in the wp-content/uploads
4
Or perhaps you want to select the entire url for any images that are resized: Working Demo
$1 selects any url that contains the wp-content/uploads with any year/month folder and which has a resized image (ex: containing -123×456.jpg)
I used #2 above when setting up redirects for all the images when migrating a WordPress website. We no longer wanted to use the YYYY/MM folders and we had different image resize proportions. The regex allowed the old images to redirect to the full-size image so at least they aren’t simply getting a 404.