WordPress.org

Make WordPress Core

Opened 12 months ago

Closed 9 months ago

Last modified 9 months ago

#24232 closed defect (bug) (fixed)

Don't Use the_title Filter in get_adjacent_post_rel_link()

Reported by: mordauk Owned by: markjaquith
Milestone: 3.6 Priority: normal
Severity: major Version: 2.8
Component: Template Keywords: has-patch commit needs-codex
Focuses: Cc:

Description

The get_adjacent_post_rel_link() function applies the the_title filter to the post title before setting it up in the <link> tags.

It's really common for the the_title filter to be used to modify the actual HTML markup of post titles (see this example for adding product micro data), but this results in improperly formatting <link> tags. See this github issue for an example of the result.

get_adjacent_post_rel_link() should be using an equivalent to the_title_attribute() instead. Since there is not a get_the_title_attribute() function, I propose two options:

  1. Introduce a get_the_title_attribute( $post_id ) function and then use this in get_adjacent_post_rel_link()
  1. Simply remove apply_filters() and add in esc_attr( strip_tags( $title ) ) instead.

My vote would be to introduce a get_the_title_attribute() function.

Attachments (3)

adjacent_post_rel_link.diff (547 bytes) - added by mordauk 11 months ago.
24232.diff (943 bytes) - added by markjaquith 9 months ago.
24232.2.diff (1.8 KB) - added by markjaquith 9 months ago.

Download all attachments as: .zip

Change History (17)

comment:1 mordauk12 months ago

  • Cc pippin@… added

comment:2 sunnyratilal12 months ago

  • Cc ratilal.sunny@… added

comment:3 mordauk11 months ago

  • Keywords has-patch added; needs-patch removed

I'm opting for simply removing the "the_title" filter.

comment:4 bungeshea9 months ago

  • Cc info@… added

comment:5 sunnyratilal9 months ago

  • Cc sunny@… added
  • Severity changed from normal to major
  • Version set to trunk

comment:6 markjaquith9 months ago

Hmm. I don't know. Injecting HTML like that seems wrong. Or that it should at least have an "in the loop" safety check. But that's besides the point. We should be using the_title_attribute() here (it has an echo flag).

comment:7 markjaquith9 months ago

Doh. But you can't pass in a post ID to the_title_attribute(). It is loop-only.

We can't lose the the_title filter here... that would be unexpected. We should, however, strip tags. Patch coming.

markjaquith9 months ago

markjaquith9 months ago

comment:8 markjaquith9 months ago

  • Milestone changed from Awaiting Review to 3.6
  • Owner set to markjaquith
  • Status changed from new to accepted

24232.2.diff Alternative approach: allow the_title_attribute() to take a post argument.

Note that this doesn't solve mordauk's issue. Instead, Pippin, I suggest that you put a safety check on your callback such that it bails if ! did_action( 'wp_head' ).

comment:9 nacin9 months ago

  • Keywords commit added

+1 commit on 24232.2.diff.

comment:10 markjaquith9 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 24783:

Allow the_title_attribute() to receive a post argument, and use this in get_adjacent_post_rel_link() to make sure tags are stripped from the title output there.

Fixes #24232.

comment:11 mordauk9 months ago

Excellent, thanks Mark.

comment:12 DrewAPicture9 months ago

  • Keywords needs-codex added

See [24783] for new $post arg in the_title_attribute()

comment:13 SergeyBiryukov9 months ago

  • Version changed from trunk to 2.8

comment:14 Jayjdk9 months ago

#14804 was marked as a duplicate.

Note: See TracTickets for help on using tickets.