How to make my site use HTTPS for images or how to insert images as relative paths?

Main Issue As long as you are accessing the WordPress dashboard via HTTPS, new media items should be inserted into content using HTTPS in the associated media item URL. There is a bit more detail around that feature in this WordPress ticket: wp_get_attachment_url returns https when it should not. That ticket describes how wp_get_attachment_url returns … Read more

Conflict with single and double quotes

It’s sometimes easier to work with sprintf(): ‘Default’ => sprintf( ‘<img src=”https://wordpress.stackexchange.com/questions/213508/%s/admin/images/default.png” width=”120″ height=”80″ alt=”%s” />’, get_template_directory(), esc_attr__( ‘Default’, ‘my_theme’ ) ); where we use the esc_attr__() to return a translated value that’s safe to be used in an attribute, but I’m not sure what your THEMEROOT contains, so I just replaced it with get_template_directory().

Adding Static Image to WooCommerce Content-Single-Product template

Many thanks to Nathan Powell for the fix. Changing get_stylesheet_directory() to get_stylesheet_directory_uri() will return the correct URL. get_stylesheet_directory() returns the absolute server path to child or parent theme (hence my previous issue) whereas get_stylesheet_directory_uri() returns the properly formed URI of child or parent theme. I suppose the lesson is to pay close attention to exactly … Read more

Limit dimensions of “Full” size images

So I’ve found this WP_Image_Editor in the CodeX. Basically by adding the code below it should automatically resize an image 🙂 Code: $image = wp_get_image_editor( ‘cool_image.jpg’ ); // Return an implementation that extends WP_Image_Editor if ( ! is_wp_error( $image ) ) { $image->resize( 300, 300, true ); $image->save( ‘new_image.jpg’ ); } I don’t know exactly … Read more

Division by zero error in image.php

shutter speed is one of the exif data wordpress tries to extract from images when uploaded. If the image do not contain the info it will be zero, hence your division by zero error. Somewhere before that code you should check if the image even needs to go there. If it is not a photo … Read more

One of my image sizes isn’t showing up in srcset

Just gong to post the answer here too. @Dan linked to another question that had the answer. Here’s some documentation on the new responsive images feature: Responsive Images in WordPress 4.4 The default max-size that will go into a srcset is 1600px wide. So if you plan on using images that are bigger than that, … Read more

How to get image from media library with URL [duplicate]

I believe you will need this function: wp_get_attachment_image_src(); (Here is the codex link: https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/) All you have to do is pass in the ID of the image you wish to fetch and it will give you the URL. A little example: <?php // Getting the media attached to a post $post_image_url = wp_get_attachment_image_src($post->ID); // var_dump … Read more