Output post thumbnail (add class)

Use wp_get_attachment_image() instead if you want to set a class property. Example: $image = wp_get_attachment_image( get_post_thumbnail_id(), array(100, 100), true, array(‘class’ => ‘your-class-name’) ); //returns the HTML for the attachment echo $image; The above function returns the HTML img tag: <img src=”http://example.com/path/to/image.jpg” class=”your-class-name”/> You can see the difference between functions here: https://developer.wordpress.org/reference/functions/wp_get_attachment_image/ https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/

Set spesific size of featured images

In your functions.php you want to issue a call to set_post_thumbnail_size() https://codex.wordpress.org/Function_Reference/set_post_thumbnail_size As with add_image_size, you provide the target width, height & whether you want the image hard cropped to these dimensions. So, for example, set_post_thumbnail_size(427, 427, true); will crop all your thumbnails to be a maximum of 427px high or wide, depending on aspect … Read more

WordPress PNG compression issue

This probably has to do with the ImageMagick library that WP normally uses to resize images. I’m not sure whether it is possible to modify the standard settings WP applies, but it is possible to define your own. Here is a tutorial for that. You would have to replace the filter in that tutorial with … Read more

Different Featured Images depending on context: loop or single view

The easiest way to achieve this is to use the Multiple Post Thumbnails plugin. Once you have done this, add the following snippet to your functions file: if (class_exists(‘MultiPostThumbnails’)) { new MultiPostThumbnails(array( ‘label’ => __(‘Secondary Featured Image’, ‘yourtextdomain’) ‘id’ => ‘secondary-image’, ‘post_type’ => ‘post’ )); } This will make a box ‘Secondary Featured Image’ available … Read more