Easily Add Featured Images to the Bottom of Your WordPress Blog Posts

To display the featured image at the bottom of every WordPress post, you can add the following code snippet to your child theme’s functions.php file:

function add_featured_image_to_bottom($content) {
    if (is_singular('post') && is_main_query()) {
        if (has_post_thumbnail()) {
            $featured_image = get_the_post_thumbnail(null, 'full', array('class' => 'featured-image-bottom'));
            $content .= '<div class="featured-image-wrapper" style="margin-top: 30px;">' . $featured_image . '</div>';
        }
    }
    return $content;
}
add_filter('the_content', 'add_featured_image_to_bottom');
Code language: PHP (php)

Explanation:

  • is_singular('post') ensures it only runs on single post pages.
  • is_main_query() avoids affecting secondary queries (e.g., in widgets).
  • get_the_post_thumbnail() fetches the featured image.
  • The image is appended to the bottom of the post content using the the_content filter.

Optional: Custom Styling via CSS

You can also style it by adding this to your child theme’s style.css:

.featured-image-bottom {
    width: 100%;
    height: auto;
    display: block;
    margin-top: 20px;
    border-radius: 8px;
}
Code language: CSS (css)


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *