Languages: English • (Add your language)
Gets the direct image URL for the featured image of the current post.
This tag must be used within The Loop.
Use has_post_thumbnail()
to check whether a Feature Image has been added to the post.
To enable post thumbnails, the current theme must include add_theme_support( 'post-thumbnails' );
in its functions.php file. See also Post Thumbnails.
<?php the_post_thumbnail_url( $size ); ?>
PLEASE NOTE: The crop does not work in WP 3.0+. All that is needed for WP 3.0+ is the call for the thumbnail to post. Then proceed to media in the dashboard and set your thumbnail to crop to the size you wish to use.
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail_url(); } ?> <?php the_content(); ?>
The default image sizes of WordPress are "thumbnail", "medium", "large" and "full" (the size of the image you uploaded). These image sizes can be configured in the WordPress Administration Media panel under Settings > Media. This is how you can use these default sizes with the_post_thumbnail():
the_post_thumbnail_url(); // without parameter -> 'post-thumbnail' the_post_thumbnail_url( 'thumbnail' ); // Thumbnail (default 150px x 150px max) the_post_thumbnail_url( 'medium' ); // Medium resolution (default 300px x 300px max) the_post_thumbnail_url( 'large' ); // Large resolution (default 640px x 640px max) the_post_thumbnail_url( 'full' ); // Full resolution (original size uploaded) the_post_thumbnail_url( array(100, 100) ); // Other resolutions
Register new image sizes for Post Thumbnails with: add_image_size().
To set the default size for Post Thumbnails see: set_post_thumbnail_size().
example 1. To link Post Thumbnails to the Post Permalink in a specific loop, use the following within your Theme's template files:
<?php if ( has_post_thumbnail() ) : ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> <img src="<?php the_post_thumbnail_url(); ?>"/> </a> <?php endif; ?>
You can use get_the_post_thumbnail_url() in the same way.
the_post_thumbnail_url() is located in wp-includes/post-thumbnail-template.php
.