Using concatenate with WordPress Thumbnail

the_post_thumbnail function echoes the result and does not return anything. If you want to concatenate it this way, you should use wp_get_attachment_image instead. $list .= ‘<div>’. wp_get_attachment_image( get_post_thumbnail_id(), ‘post-thumbnail’ ) . ‘</div>’;

Show Post Thumbnail In Custom Post From Other CPT

If you want to get the post thumbnail URL, you can use get_the_post_thumbnail_url(): <?php $image_path=”images/club/” . $opposition->post_name . ‘.jpg’; // relative to the root directory if ( @file_exists( ABSPATH . $image_path ) ) { // Check the unique image first. $thumbnail = home_url( “https://wordpress.stackexchange.com/” . $image_path ); } elseif ( has_post_thumbnail( $opposition ) ) { … Read more

How to handle and keep image quality of featured image uploads

Several things could be impacting the image quality, but the biggest impact is calling the_post_thumbnail() without giving it a size. By default that will get the “thumbnail” image size, which by default is 150×150 pixels. Try this instead: the_post_thumbnail(‘full’, array(‘class’ => ‘ responsiveThumbnail’)); Then you’ll be pulling the full-size image rather than the autogenerated thumbnail. … Read more

Show a default image

Create “images” folder in current active theme the put “default-image.jpg” in that folder. <?php if ( has_post_thumbnail( ) ) { echo get_the_post_thumbnail( $page->ID, ‘image’ ); } else { ?> <img src=”<?php echo get_template_directory_uri().’/images/default-image.jpg’; ?>”/> <?php } ?> Use path according to the theme (parent or child). get_stylesheet_directory_uri(): url path to current Theme directory get_template_directory_uri(): url … Read more

How to display a default image for post thumbnail using functions.php?

The relevant code is in wp-includes/post-thumbnail-template.php. The thumbnail ID is stored in post metadata as _thumbnail_id. You could either upload the default image to WordPress and make its ID the default thumbnail ID for any post that doesn’t have one: function default_post_metadata__thumbnail_id( $value, $object_id, $meta_key, $single, $meta_type ) { if ( ‘_thumbnail_id’ == $meta_key ) … Read more

How do I set “Upload Image” as detault “Set Featured Image” window?

WordPress exposes media upload component globally, as well the featured image modal with wp.media.featuredImage so developers can interact with it. FeaturedImage component uses the wp.media.frame which is a Backbone component, which has custom event attached to it. There’s not much documentation on it, you can check the source here. You can use the following snippet … Read more

MultiPostThumbnail and the_post_thumbnail

In code you posted you have issue with syntax – you should stick either with braces style or colons style, mixing them is not supported. if(class_exists(‘MultiPostThumbnails’) && MultiPostThumbnails::has_post_thumbnail(‘post’, ‘secondary-image’)) { MultiPostThumbnails::the_post_thumbnail(‘post’, ‘secondary-image’, NULL, ‘post-secondary-image-thumbnail’); } else { the_post_thumbnail(); }