Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24232 closed defect (bug) (fixed)

Don't Use the_title Filter in get_adjacent_post_rel_link()

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


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 10 years ago.
24232.diff (943 bytes) - added by markjaquith 10 years ago.
24232.2.diff (1.8 KB) - added by markjaquith 10 years ago.

Download all attachments as: .zip

Change History (17)

#1 @mordauk
10 years ago

  • Cc pippin@… added

#2 @sunnyratilal
10 years ago

  • Cc ratilal.sunny@… added

#3 @mordauk
10 years ago

  • Keywords has-patch added; needs-patch removed

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

#4 @bungeshea
10 years ago

  • Cc info@… added

#5 @sunnyratilal
10 years ago

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

#6 @markjaquith
10 years 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).

#7 @markjaquith
10 years 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.

10 years ago

10 years ago

#8 @markjaquith
10 years 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' ).

#9 @nacin
10 years ago

  • Keywords commit added

+1 commit on 24232.2.diff.

#10 @markjaquith
10 years 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.

#11 @mordauk
10 years ago

Excellent, thanks Mark.

#12 @DrewAPicture
10 years ago

  • Keywords needs-codex added

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

#13 @SergeyBiryukov
10 years ago

  • Version changed from trunk to 2.8

#14 @Jayjdk
10 years ago

#14804 was marked as a duplicate.

Note: See TracTickets for help on using tickets.