Created
July 6, 2023 06:39
-
-
Save chekle/bf71d51d0ea8c7584c34baa6f3f3ce22 to your computer and use it in GitHub Desktop.
WordPress Featured Image Examples
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
// Enable featured images for blog posts | |
add_theme_support( 'post-thumbnails' ); | |
// Enable for specific CPT or Events Calendar | |
add_theme_support( 'post-thumbnails', [ | |
'post', | |
'page', | |
'tribe_events', | |
] ); | |
// Usage bg image | |
<?php if ( has_post_thumbnail() ) { ?> | |
<div class="news-featured-image" | |
style="background-image:url('<?php echo get_the_post_thumbnail_url( null, 'full' ); ?>');"> | |
</div> | |
<?php } ?> | |
// Usage normal | |
<?php if ( has_post_thumbnail()) : ?> | |
<?php the_post_thumbnail(); ?> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment