Skip to content

Instantly share code, notes, and snippets.

@AchalJ
Created January 19, 2022 17:07
Show Gist options
  • Save AchalJ/80472374884c5741103790ede21ffb54 to your computer and use it in GitHub Desktop.
Save AchalJ/80472374884c5741103790ede21ffb54 to your computer and use it in GitHub Desktop.
Post Featured Image Shortcode
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