WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 22 months ago

#24348 closed enhancement (invalid)

Consider the post thumbnail in get_the_post_format_image()

Reported by: tollmanz Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.6
Component: Post Formats Keywords: has-patch dev-feedback needs-refresh
Focuses: Cc:

Description

get_the_post_format_image() makes valiant attempts to locate an image for use with a post of image post format.

The function first attempts to find suitable data in the post format meta field. If no image is found there, it grabs the first attached image. Finally, if all else fails, it will look in the post content to use the first image inserted in the content.

I think that the function should also consider grabbing the post's featured image as a fallback. I would prioritize this right after the post format meta data.

I think this is important in that it seems that using the featured image was a common practice for adding an image to a post of image post format. I would think that this would help improve back compat for themes that have used this practice. Moreover, since grabbing an attached image or an image inserted in the post content is merely a guess at the right image to use for the post, I think that using the featured image is a better guess than either of these methods.

Attachments (3)

24348.patch (641 bytes) - added by tollmanz 2 years ago.
24348.1.patch (1.0 KB) - added by tollmanz 2 years ago.
24348.2.patch (553 bytes) - added by tollmanz 2 years ago.

Download all attachments as: .zip

Change History (14)

@tollmanz2 years ago

comment:1 @tollmanz2 years ago

24348.patch shows how I think this could be implemented.

comment:2 @knutsp2 years ago

Using the featured image should be the last option. The featured image is mean to represent the entire post, alone or along with an excerpt, in multi post views. Many themes don't show them in singe post views, as the featured image is not considered to to a part of the post content.

The first attached or inserted image should be a higher priority than the featured image when looking for a post format image.

comment:3 @tollmanz2 years ago

Hi @knutsp! Thanks for the response! I think what you are saying makes a lot of sense. I would be fine with the Featured Image being the last resort. I still think that it is a legitimate image source to consider when trying to find the an image to display for the image post format.

@tollmanz2 years ago

comment:4 @tollmanz2 years ago

24348.1.patch will grab the Featured Image as the last option for finding an image related to the post. Additionally, I added the @return docblock information and made sure to always return a string value.

comment:5 @jeremyfelt2 years ago

+1 for this.

Many of my imagined use cases for post formats are associated with mobile. The current WordPress iOS app has Set Featured Image right below the Post Format selection, which encourages me to use that to post quick images. I was surprised last night to find out that an image post showed up blank in Twenty Thirteen on any view. Workflow and UI may change in the app over time, but it makes sense to keep looking through the chain if an image has not yet been found.

comment:6 @SergeyBiryukov2 years ago

  • Milestone changed from Awaiting Review to 3.6

comment:7 @DrewAPicture2 years ago

  • Keywords has-patch dev-feedback added

comment:8 @SergeyBiryukov2 years ago

In 24352:

Add @return for get_the_post_format_image(). Make sure the function always returns a string. props tollmanz. fixes #24414. see #24348.

comment:9 @SergeyBiryukov2 years ago

  • Keywords needs-refresh added

@tollmanz2 years ago

comment:10 @tollmanz2 years ago

Patch refreshed after r24352.

comment:11 @wonderboymusic22 months ago

  • Milestone 3.6 deleted
  • Resolution set to invalid
  • Status changed from new to closed

these functions should be moved to the plugin - see #24610

Note: See TracTickets for help on using tickets.