How do you modify the HTML output of a Gallery item (using the gallery shortcode)?

Let’s assume that your theme is NOT rolling its own gallery shortcode, and let’s assume that you’re using the shortcode rather than the ‘gallery’ post format here. What you’re looking for is the ‘gallery_shortcode’ function within wp-includes/media.php around line 750 (as of 3.3.1). That’s where the HTML output of your gallery items is hard-coded. Of … Read more

How to reduce original image quality on upload?

In general I wouldn’t recommend modifying the original uploaded image files, just in case we might need to re-generate intermediate sizes. But let’s see if it’s possible 🙂 We can in general let WordPress choose the image editor, that depends on modules like GD or Imagick, through: $editor = wp_get_image_editor( $file ); but this can … Read more

Strange img srcset behaviour

After some further digging, I discovered that the max srcset size in WordPress 4.4 is set to 1600px wide by default. You can fix this by adding the following filter: add_filter( ‘max_srcset_image_width’, ‘max_srcset_image_width’, 10 , 2 ); function max_srcset_image_width() { return 2048; } The helper function and this information is thanks to: http://aaronrutley.com/responsive-images-in-wordpress-with-acf

Extend WP Customizer to make multiple image selection possible

What I eventually did was extending the WP_Customize_Control class as follows: <?php if (!class_exists(‘WP_Customize_Image_Control’)) { return null; } class Multi_Image_Custom_Control extends WP_Customize_Control { public function enqueue() { wp_enqueue_style(‘multi-image-style’, get_template_directory_uri().’/css/multi-image.css’); wp_enqueue_script(‘multi-image-script’, get_template_directory_uri().’/js/multi-image.js’, array( ‘jquery’ ), rand(), true); } public function render_content() { ?> <label> <span class=”customize-control-title”>Image</span> </label> <div> <ul class=”images”></ul> </div> <div class=”actions”> <a class=”button-secondary upload”>Add</a> … Read more

Download external images if post is publish

Scheduled posts don’t trigger publish_post, only updating the post itself will do that. Add an action for future_to_publish, see the reference on post status transitions. I don’t believe that you’ll have access to the user-object in that case, so you might want to refactor that. Alternatively, just get the images when the user saves the … Read more

Best image hosting service

Its not recommended often enough, but Flickr is an excellent image host for blogs as well. Their pro account costs only $25/year. You get unlimited image, video uploads and no bandwidth limit. If you don’t want your blog image uploads populating your personal photostream, you can easily create a separate account for it. You can … Read more