max image width in url with w=###
-
I can append ?w=### or ?h=### onto an image url to set maximum width or height served but can I specify BOTH max width and max height in the url address ? And/or is there a way to alternatively choose a default width by appending something like ?size=medium_large to get a max width of 768px ?
The blog I need help with is: (visible only to logged in users)
-
Hi there,
Can you tell me a bit more about what you are trying to set up? WordPress will size your images automatically based on the available space provided by your theme, so those image dimensions (you sometimes see in image URLs) are calculated by WordPress, and not something you need to construct manually.
Are you trying to display images larger that what your theme allows? Or did you have some other purpose in mind? Thanks for the additional info!
-
Hi and thank you for replying. I am working with my site hosted at wordpress.com (not hosting myself). I am pulling the RSS from the site and “digesting” into html to be displayed on another website of mine. I notice that appending ?w=### or ?h=### to the image url being displayed will cause wordpress to serve an image of some maximum width or height which means smaller image (less data transfer) yet plenty big for the container it is displayed in which is usually 768px width. I have decided that appending ?h=576 will be a good choice since the class of the image being displayed will have css property maxWidth:100% .. this should keep the image transfer down and display well. My question was if there is a way to append BOTH w=### AND h=### to restrict maximum width and height of the image being served .. I have not seen this working since wordpress seems to “honor” only the first of the two. Anyway, I’m happy with just ?h=576 appended for my purpose.
-
Here is an example :
https://shopdaddy.files.wordpress.com/2020/09/protest_640.jpg?w=450&h=200
You see the served image will be 450×300 ignoring the h=200 appended onto the url.
But I’m ok with this since I can use
https://shopdaddy.files.wordpress.com/2020/09/protest_640.jpg?h=200 if I want to get an image with height of 200px served. This should be good.
My primary reason for doing this is to cut down on data transfer.
Thank You ! -
Last thing : If there was something I could include in the URL that would serve the “medium_large” size of width 768px then that could be interesting as well but I haven’t found any documentation or forum info about anything in a URL that would choose one of the “default” image sizes.
-
My question was if there is a way to append BOTH w=### AND h=### to restrict maximum width and height of the image being served
This is not possible as far as I know, no.
Last thing : If there was something I could include in the URL that would serve the “medium_large” size of width 768px then that could be interesting as well but I haven’t found any documentation or forum info about anything in a URL that would choose one of the “default” image sizes.
I don’t think that’s possible either. From my understanding there’s a fixed list of parameters that can be used as query strings in a URL, and you can’t just make up your own. The identifiers for image size presets in WordPress are something defined by WordPress itself, in the underlying PHP code, and not existing supported query strings for URLs.
You might find something in the technical documentation for the WordPress software itself over at https://wordpress.org/support/
You can also try asking the community over there for advice on whether it’s possible in WordPress generally. If it is, it will most likely also work on WordPress.com, but I can’t guarantee that :)
-
This is not possible as far as I know, no.
Sorry, I’d meant to expand on this. As far as I know, if you add both those query strings, the browser will use the one that corresponds with the longer edge of the image, ignoring the other one, so as to preserve the image aspect ratio.
- The topic ‘max image width in url with w=###’ is closed to new replies.