Add custom images sizes to WordPress


/ Published in: PHP
Save to your folder(s)

- Use custom image size within template (including if exist)
- Add a class name to a custom image size


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.