Opened 9 years ago
Closed 9 years ago
#39302 closed defect (bug) (fixed)
Twenty Seventeen: Featured image not displayed on single template
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.7.1 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Bundled Theme | Keywords: | has-patch |
| Focuses: | Cc: |
Description
I assigned a featured image to a post and it appeared as expected in the loop. When I navigated to a given post that had the featured image, however, it was nowhere to be seen. In looking further, the call to display the featured image is in header.php before the_post() is called and thus the $post global is not set. This means that has_post_thumbnail() return false and no featured image will be set. To reliably get the featured image, we need to explicitly pass in get_queried_object_id().
Attachments (2)
Change History (9)
#1
@
9 years ago
- Keywords has-patch added
- Owner set to davidakennedy
- Status changed from new to assigned
#3
@
9 years ago
Humm. I can't reproduce this anymore either. It might have been a plugin that failed to do wp_reset_postdata() before get_header() is called. Nevertheless I think the theme would be more robust if it explicitly referenced the main queried post rather than assume that $post global is set.
#4
@
9 years ago
+1 for hardening the logic per 39302.0.diff, but let's also include an inline comment explaining why $post may not be what you'd expect it to be here.
Hey @westonruter! Thanks for the report!
Can you provide some screenshots or what you're seeing? And describe where you're expecting the featured image to show up?
I tested this, both with posts and pages. With existing ones and new ones and wasn't able to reproduce the lack of a featured image when viewing the single post and/or page.