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

Image dimensions same as image size

No, it won’t create a new image that is exactly the same size.. nor should it. All the thumbnail, medium, and large images are resized images, by definition. Since the original image is already 600×600, there’s no point in creating another file at the same size, but with a lower quality (remember that JPEG compression … Read more

Impose a Maximum Limit on Image height and width upload size

Basically you just retrieve the info via getimagesize(), a basic PHP function, a then handle your errors with notes. The plugin A basic plugin as a starting point: <?php /** Plugin Name: (#67107) »kaiser« Restrict file upload via image dimensions */ function wpse67107_restrict_upload( $file ) { $file_data = getimagesize( $file ); // Handle cases where … Read more

Get attachment by slug

An attachment is just a post with the post_status = inherit and the post_type = attachment, so can be queried with WP_Query or get_posts. Note that slug (post_name) is unique per post type. $_header = get_posts(‘post_type=attachment&name=book-site-header&posts_per_page=1&post_status=inherit’); $header = $_header ? array_pop($_header) : null; $header_url = $header ? wp_get_attachment_url($header->ID) : ”; you can also use the … Read more