Created
January 19, 2022 17:07
-
-
Save AchalJ/80472374884c5741103790ede21ffb54 to your computer and use it in GitHub Desktop.
Post Featured Image Shortcode
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
add_shortcode( 'cg_post_featured_image', function( $attrs ) { | |
$args = wp_parse_args( $attrs, array( | |
'linked' => 'yes', | |
) ); | |
$image = get_the_post_thumbnail( $post, $settings->size, array( | |
'itemprop' => 'image', | |
'class' => 'post-featured-image', | |
) ); | |
if ( $image && 'no' != $args['linked'] ) { | |
$href = get_the_permalink(); | |
$title = the_title_attribute( array( | |
'echo' => false, | |
) ); | |
return "<a href='{$href}' title='{$title}'>{$image}</a>"; | |
} else { | |
return $image; | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment