Posted By

thescottlee on 06/08/12


Tagged

wordpress functions images


Versions (?)

Add custom images sizes to WordPress


 / Published in: PHP
 

  • Use custom image size within template (including if exist)
  • Add a class name to a custom image size
  1. // Add Feature Image size, hard crop
  2. if ( function_exists( 'add_image_size' ) ) {
  3. add_image_size( 'feature-image', 570, 285, true );
  4. add_image_size( 'feature-image-small', 285, 285, true);
  5. add_image_size( 'feature-image-home', 285, 303, true);
  6. }
  7.  
  8. // To use the image, if feature image exist
  9. <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'feature-image' ); } ?>
  10.  
  11. // Add a class to the image
  12. <?php echo the_post_thumbnail( 'feature-image-large', array('class' => 'feature-image') ); ?>

Report this snippet  

You need to login to post a comment.