Height and width attribute not setting by the_post_thumbnail

In the 2nd attribute of the_post_thumbnail() you can give additional attributes for the image. the_post_thumbnail( ‘postbox-thumb’, array( ‘width’ => 100, ‘height’ => 100 ) ) I’ve just checked it again the width and height are set in the latest WP Versions, so you might have just to update your WordPress installation.

How can I use wp_save_image_editor_file filter?

The filter inside ~/wp-admin/includes/image.edit.php looks like this: apply_filters(‘wp_save_image_editor_file’, null, $filename, $image, $mime_type, $post_id); So a callback would look like the following: add_filter( ‘wp_save_image_editor_file’, ‘wpse91038_saved_image_editor_file’, 10, 5 ); function wpse91038_saved_image_editor_file( $saved, $filename, $image, $mime_type, $post_id ) { var_dump( $saved ); var_dump( $filename ); var_dump( $image ); var_dump( $mime_type ); var_dump( $post_id ); return $saved; } Right … Read more

wp_get_attachment_image_src returns incorrect URL on multisite

I found this stray code in the header.php $GLOBALS[blog_id] = get_option(‘woo_blog_id’); This wiped out the global variable that get_current_blog_id() relies on to get the site id in multisite. This is then used by wp_get_attachment_url() to build the appropriate URL. Because I was getting an incorrect site id, my attachment URLs were coming out wrong.

Retrieve Image Attachments Getting Post Thumbnail Image First

First, exclude the featured image (= post thumbnail) from the query, then set up the posts array as combination of the featured image and the other images. Put this directly below $args = … and above $attachments = …: if (has_post_thumbnail($post->ID)) { $featured_image = get_post_thumbnail_id($post->ID); $args[‘exclude’] = $featured_image; $attachments = array(get_post($featured_image)) + get_posts($args); } else

How to obfuscate theme directory URLs

Use get_template_directory_uri(): $url = get_template_directory_uri() . ‘/images/myimage.jpg’; This function will always return the correct path to your theme. If you want to hide/shorten that URL, you could use an endpoint, maybe img. The downside is, you load the complete WordPress for each image request. Or use mod_rewrite: RewriteRule ^img/([a-z\d-])\.png /wp-content/themes/my_theme/img/$1.png [L] This will not work … Read more

What can i do add title to ‘large’ image?

Check the Codex. the_post_thumbnail accepts two parameters, the second of which is $attr— “attributes”. the_post_thumbnail(‘full’,array(‘title’=>’yay! a title!’)); The Codex entry for the_post_thumbnail is not clear on what is and is not allowed as an “attribute” but it appears to depend on wp_get_attachment_image and by filters applied by that function. title does work though. I checked.