0

Everything For WordPress Post Thumbnails

With these functions you can do all you really need to know about for enabling and using post thumbnails in your WordPress theme.


add_theme_support( 'post-thumbnails', array( 'post' ) ); // Add it for posts
add_theme_support( 'post-thumbnails', array( 'page' ) ); // Add it for pages

set_post_thumbnail_size( 50, 50 ); // 50 pixels wide by 50 pixels tall, box resize mode
set_post_thumbnail_size( 50, 50, true ); // 50 pixels wide by 50 pixels tall, hard crop mode

add_image_size( 'single-post-thumbnail', 400, 9999 ); // Permalink thumbnail size

Use the following in your theme template where you want the thumbnail to show up.

<?php
if ( has_post_thumbnail() ) {
    // the current post has a thumbnail
} else {
    // the current post lacks a thumbnail
}
?>
<?php the_post_thumbnail(); ?>
<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
Levels: Syntax:

  1. Avatar

    Your Name
    February 4


    CommentLuv badge