Hot answers tagged

5

This is more of a general srcset and browser question, not a WordPress specific question. However, in general, you can't predict what browsers will do with the srcset information. For your specific example, it appears that you failed to clear the cache completely between your reloads. Note the 304 response indicating that your browser already has the image ...


3

A way to do it is to use the (very convenient) editor:image-edit and editor:image-update events triggered by the tinymce wpeditimage plugin to get/set the dom directly: add_action( 'admin_footer', function () { ?> <script type="text/javascript"> jQuery(function ($) { if (wp && wp.media && wp.media.events) { ...


2

This is sort of an alternative solution to doing a bunch of RegEx. Query all images attached to the post, get the thumbnail of the first and display it as thumbnail ( you could even assign it as the post thumbnail if you wanted to, to make it easier next time the loop is run ). So inside your loop you would have: if( have_posts() ) { $image_mimes = ...


2

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 ...


1

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' ); } ...


1

It looks like you use the Jetpack Plugin with Photon function (Wordpress.com photo CDN) https://jetpack.me/support/photon/ https://developer.wordpress.com/docs/photon/ You have to deactivate the Photon option in the Jetpack plugin settings.


1

Here you go: if(!current_user_can('delete_others_posts')){ /*Handling wp media uloads*/ add_filter('wp_handle_upload_prefilter','lets_handle_img_width'); function lets_handle_img_width($file) { $img = getimagesize($file['tmp_name']); $width = $img[0]; if ($width < 350){ $file['error'] = "Image is ...


1

Register a new image size with add_image_size( $name, $width, $height, $crop ). // Hard crop left top add_image_size( 'custom-size', 160, 90, array( 'left', 'top' ) ); Then use a plugin like Regenerate Thumbnails which will automatically create the new sizes on your server. You can also make your custom sizes selectable from your WordPress admin. To do ...



Only top voted, non community-wiki answers of a minimum length are eligible