Last active
June 23, 2018 03:36
-
-
Save IamSohaggazi/fce4c032b40780ca9b4ded8b3ac19cdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
the_post_thumbnail(); // Without parameter ->; Thumbnail | |
the_post_thumbnail( 'thumbnail' ); // Thumbnail (default 150px x 150px max) | |
the_post_thumbnail( 'medium' ); // Medium resolution (default 300px x 300px max) | |
the_post_thumbnail( 'medium_large' ); // Medium-large resolution (default 768px x no height limit max) | |
the_post_thumbnail( 'large' ); // Large resolution (default 1024px x 1024px max) | |
the_post_thumbnail( 'full' ); // Original image resolution (unmodified) | |
the_post_thumbnail( array( 100, 100 ) ); // Other resolutions (height, width) | |
add_image_size( 'category-thumb', 300, 9999 ); // 300 pixels wide (and unlimited height) | |
**-- create custom Featured Image sizes in your theme’s functions.php file. ** | |
if ( function_exists( 'add_theme_support' ) ) { | |
add_theme_support( 'post-thumbnails' ); | |
set_post_thumbnail_size( 150, 150, true ); // default Featured Image dimensions (cropped) | |
// additional image sizes | |
// delete the next line if you do not need additional image sizes | |
add_image_size( 'category-thumb', 300, 9999 ); // 300 pixels wide (and unlimited height) | |
Styling Featured Images #Styling Featured Images | |
Featured Images are given a class “wp-post-image”. | |
They also get a class depending on the size of the thumbnail being displayed. | |
You can style the output with these CSS selectors: | |
img.wp-post-image | |
img.attachment-thumbnail | |
img.attachment-medium | |
img.attachment-large | |
img.attachment-full | |
Display the Featured Image with a class “alignleft”: | |
the_post_thumbnail( 'thumbnail', array( 'class' => 'alignleft' ) ); | |
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(); ?>" > | |
<?php the_post_thumbnail(); ?> | |
</a> | |
<?php endif; ?> | |
To link all Post Thumbnails on your website to the Post Permalink, | |
put this in the current Theme’s functions.php file: | |
add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 ); | |
function my_post_image_html( $html, $post_id, $post_image_id ) { | |
$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>'; | |
return $html; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment