Skip to content

Instantly share code, notes, and snippets.

@schalkburger
Created February 17, 2015 09:30
Show Gist options
  • Save schalkburger/78e01aaf432c35ed2b8a to your computer and use it in GitHub Desktop.
Save schalkburger/78e01aaf432c35ed2b8a to your computer and use it in GitHub Desktop.
Wordpress post thumbnails featured image reference
<?php add_theme_support( 'post-thumbnails' ); // Add theme post thumbnails support ?>
<?php the_post_thumbnail(); // Display post thumbnail ?>
<?php set_post_thumbnail_size( 50, 50, true ); // 50 pixels wide by 50 pixels tall, crop mode // Set post thumbnail to 50 x 50 and does a hard crop ?>
<?php add_image_size( 'custom-thumb', 300, 9999 ); //300 pixels wide (and unlimited height) // Set post thumbnail to 300 x any height, no cropping ?>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'custom-thumb' ); } else { ?> <img src="<?php bloginfo('template_directory');?>/img/thumb-default.png" alt=""/> <?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment