How to show scaled featured image in template?

You can create custom size image with add_image_size() in the functions.php function add_custom_size_images() { // Add image size width 300 with unlimited height. add_image_size( ‘featured-image-300’, 300 ); } add_action( ‘after_setup_theme’, ‘add_custom_size_images’ ); And in the template to get the size that you created with the_post_thumbnail() the_post_thumbnail( ‘featured-image-300’ ); Notice: If you want it to work … Read more

Multiple Post Thumbnails plugin and attachment error

You should trigger the function on some other hook like function add_multiple_post_thumbnails_from_plugin() { new MultiPostThumbnails( array( ‘label’ => ‘Thumbnail Image’ ,’id’ => ‘video-thumbnail’ ,’post_type’ => ‘video’ ) ); } add_action( ‘admin_init’, ‘add_multiple_post_thumbnails_from_plugin’ );

How to add a featured image to a existing post via php?

The trick is media_sideload_image() and set_post_thumbnail(). media_sideload_image() assumes you can grab the URL to the image, whether it exist in /wp-content/ or somewhere else (another site, even). As long as you can programmatically reference the image’s URL, something like this should work. $image=”image.jpg”; $media = media_sideload_image($image, $post->ID); if(!empty($media) && !is_wp_error($media)){ $args = array( ‘post_type’ => … Read more

How to display a post’s Featured Image with this code?

Modify your function as such: // This theme displays custom size (page-single) featured image on the Post’s page function InsertFeaturedImage($content) { global $post; $original_content = $content; if ( current_theme_supports( ‘post-thumbnails’ ) ) { if ((is_page()) || (is_single())) { $content = get_the_image( array( ‘size’ => ‘full’ ) ); $content .= $original_content; } } return $content; } … Read more

Thumbnail with different sizes

Intermediate image sizes are discrete, not variable. When you define an image size, with specific dimensions (whether hard-cropped or box-resized), WordPress will create a discrete image, with the specified dimensions. Otherwise, if width could be defined dynamically, WordPress would have to create a prohibitively large number of images, just to account for responsiveness. To account … Read more