Add retina “2x” in attribute “srcset”

WordPress puts all resized versions of an image with the same aspect ratio into the srcset property. So if you need a “2x” image and one is not being generated already you could add an image size via add_image_size(). For the 2x image to be inserted in the correct circumstances you might need to tweak … Read more

Images don’t load erratically

I see multiple messages about images and some script blocked in Chrome with (blocked:mixed-content) reason. Which basically means it doesn’t like unsecure http resources in secure https site. WordPress doesn’t handle this particularly well. It is designed to use absolute URLs and they tend to end up hardcoded in content and such. You would have … Read more

Search by Attachment ID

The WP_Query class can match IDs as well as search terms. An idea would be to use the pre_get_posts action to detect if the search term is numeric and, if it is, set the query to work with attachments while passing the search as the ID. function wpse223307_allow_search_by_attachment_id( $query ) { //Only alter the query … Read more

How to apply image alt descriptions from media library?

From the Dashboard of your WordPress website, go to Media > Library You will see all of your images there. Select the image which one you want to update, and click “Edit”. The “Edit Media” page will open. Scroll down to the bottom of this page, you will be found few input boxes to provide … Read more

How to get the title of the random images from media library?

Your first function get_images_from_media_library() only returns images guid, I’d suggest to extend it by returning all image datas : function get_images_from_media_library() { $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ =>’image’, ‘post_status’ => ‘inherit’, ‘posts_per_page’ => 6, ‘orderby’ => ‘rand’ ); $query_images = new WP_Query( $args ); $images = array(); foreach ( $query_images->posts as $image) { … Read more

How to setting up the custom size thumbnail for wp_get_attachment_thumb_url()?

I meant you should use wp_get_attachment_image_src() with your $cat_thumb_id. Try this: $cat_thumb_id = get_woocommerce_term_meta($cat->term_id, ‘thumbnail_id’, true); $cat_thumb = wp_get_attachment_image_src($cat_thumb_id, ‘medium_large’); $cat_thumb_src = $cat_thumb[0] ? esc_url($cat_thumb[0]) : mytheme_catch_that_image(); ?><img src=”https://wordpress.stackexchange.com/questions/226005/<?php echo $cat_thumb_src; ?>” alt=”<?php echo $cat->name; ?>”/>

Convert canvas to image and upload image to server

Since the file you send is base64 encoded, you will need to decode and save the result into a file at a temp directory. From there it is just a normal server side wordpress image manipulation and insertion of the relevant info into the DB, something that there are many examples for on this site. … Read more