Skip to content

Selah.

Pause, and calmly think on that.

Menu
  • About
  • Free Gift
  • Highlights
  • The New Covenant
  • Thoughts
    • Personal Thoughts
    • Famous Thoughts
    • Random Thoughts
Menu

How to fix WordPress Twenty Eleven Featured Image

Posted on March 21, 2015 by Matt

I like the Twenty Eleven theme and I still haven’t upgraded it. Luckily, some people are keeping it up to date and compatible with the latest WordPress in 2015! But there was one bug that bothered me for a long time and that was featured images were broken. These are the big header images at the top of posts (for example, the big image at the top of this post, or the grid of cars image at the top of one of my other posts). These image are just broken and will not display your custom featured image in the stock Twenty Eleven. So here’s how I fixed it…

git diff of my fix for twenty eleven theme featured images
diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
diff --git a/wp-content/themes/twentyeleven/header.php b/wp-content/themes/twentyeleven/header.php
index f48e4cf..a9aca8a 100644
--- a/wp-content/themes/twentyeleven/header.php
+++ b/wp-content/themes/twentyeleven/header.php
@@ -86,8 +86,10 @@
                                                 * This result would be the suggested width if the theme were to implement flexible widths.
                                                 */
                                                $header_image_width = get_theme_support( 'custom-header', 'width' );
+                                               $header_image_height= get_theme_support( 'custom-header', 'height' );
                                        } else {
                                                $header_image_width = HEADER_IMAGE_WIDTH;
+                                               $header_image_height = HEADER_IMAGE_HEIGHT;
                                        }
                                        ?>
                        <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
@@ -97,10 +99,11 @@
                                         * Check if this is a post or page, if it has a thumbnail, and if it's a big one
                                         */
                                        if ( is_singular() && has_post_thumbnail( $post->ID ) &&
-                                                       ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ) ) &&
-                                                       $image[1] >= $header_image_width ) :
+                                                       ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ) )
+                                                       ) :
                                                // Houston, we have a new header image!
                                                echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
+                                               echo "<!-- here1 -->";
                                        else :
                                                // Compatibility with versions of WordPress prior to 3.4.
                                                if ( function_exists( 'get_custom_header' ) ) {
@@ -110,6 +113,7 @@
                                                        $header_image_width  = HEADER_IMAGE_WIDTH;
                                                        $header_image_height = HEADER_IMAGE_HEIGHT;
                                                }
+                                               echo "<!-- here2 -->";
                                                ?>
                                        <img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" />
                                <?php endif; // end check for featured image or standard header ?>

The only thing I really did here was remove the && $image[1] >= $header_image_width condition which was preventing the feature image from displaying. Ignore the other diffs, I must have committed that stuff by accident while playing around. :)

Hope this helps! Good luck!

  • Share
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to email a link to a friend (Opens in new window)

Comment Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Merry Christmas 2022
  • YouTube Finds: Song for a Winter’s Night Cover
  • Must Watch YouTube: In Defense Of Sucker Punch
  • Must Watch YouTube: Full Metal Jacket: Born Again Hard
  • Must Watch YouTube: The Philosophy of J.R.R. Tolkien: Why Things Keep Getting Worse

bible book canada centos christ christian christmas church creation evolution faith family game genesis God gog good google government heart iracing jesus life linux lord love matthew music pc poem poetry quote racing romantical salvation science sim sin steam truth update video windows word YouTube

Log in
© 2023 Selah. | Powered by Superbs Personal Blog theme