Each post currently requires the featured image
to be duplicated within the post several times.
Is there any way in which I could dynamically call the featured image
back into the post rather than manually inserting the image again several times?
UPDATE
I would also like to be able to show the image’s caption
and permalink
if possible.
Register the shortcode, ideally in a plugin or functions.php if you have to.
add_shortcode('thumbnail', 'thumbnail_in_content');
function thumbnail_in_content($atts) {
global $post;
return get_the_post_thumbnail($post->ID);
}
Add the shortcode to you post content.
[thumbnail]
If you want more features, see this post or the pastebin.
ADDING CAPTIONS AND LINKS
add_shortcode('thumbnail', 'thumbnail_with_caption_shortcode');
function thumbnail_with_caption_shortcode($atts) {
global $post;
// Image to display
$thumbnail = get_the_post_thumbnail($post->ID);
// ID of featured image
$thumbnail_id = get_post_thumbnail_id();
// Caption from featured image's WP_Post
$caption = get_post($thumbnail_id)->post_excerpt;
// Link to attachment page
$link = get_permalink($thumbnail_id);
// Final output
return '<div class="featured-image">'
. '<a href="' . $link . '">'
. $thumbnail
. '<span class="caption">' . $caption . '</span>'
. '</a>'
. '</div>';
}
RESOURCES
get_the_post_thumbnail
get_post_thumbnail_id
WP_Post
get_post
get_permalink
- Shortcode API
- Get image captions for images on gallery post format metabox