wordpress - Displaying specific thumbnail size in single.php -


currently i'm building wordpress theme , i'm trying display specific image size, cropped in single.php, , on individual post pages , not having luck.

here's functions.php:

add_theme_support( 'post-thumbnails' ); add_image_size('new-thumbnail-size',600,340, true); 

here's single.php:

<?php if( get_the_post_thumbnail() ) : ?>     <div class = 'postimgcon'>         <div class="feat-img">              <?php the_post_thumbnail('new-thumbnail-size'); ?>         </div>     </div>  <?php endif; ?>  

any ideas?

you're using correct functions declare support post thumbnails , add image size need inside after_setup_theme hook.

inside functions.php change:

add_theme_support( 'post-thumbnails' ); add_image_size('new-thumbnail-size',600,340, true); 

to:

function wpse_setup_theme() {     add_theme_support( 'post-thumbnails' );      add_image_size( 'new-thumbnail-size', 600, 340, true ); } add_action( 'after_setup_theme', 'wpse_setup_theme' ); 

also you're using wrong function check if post has thumbnail. should still work here's correct approach.

inside single.php change:

<?php if( get_the_post_thumbnail() ) : ?> 

to:

<?php if ( has_post_thumbnail() ) : ?> 

finally need aware images you've uploaded won't have been cropped 600 x 340 won't output you're expecting. need regenerate existing images. take @ following plugin that: https://wordpress.org/plugins/regenerate-thumbnails/


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -