Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#49805 new defect (bug)

missing get_the_title / confusing the_title filter

Reported by: thomask's profile thomask Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.5
Component: Posts, Post Types Keywords: reporter-feedback
Focuses: template Cc:

Description

I and probably many others (e.g. #39848) got problems with filtering H1 - the problem is, that in most templates (and also in twenty twenty) there is no way how to filter H1.

There is the_title function, that encloses the get_the_content() result with defined prefix and suffix, but this the_title function has no filter!

And what is VERY confusing - there is the_title filter, but that filter is not called from the_title function, but from get_the_title function!

I understand that it would be probably very difficult to move that the_title function where it belongs and replace it with proper get_the_title filter, but i believe there must be some quick way, e.g. that proposed wrap (but i would recommend to add all the arguments of the the_title function, so resulting in apply_filters( 'the_title_wrap', $title, $before, $after, $echo ); This way we could easily filter the result based on any option.

Change History (3)

#1 @roytanck
5 years ago

Hi Thomask. I'm trying to understand what you are trying to achieve here. As far as I know, the the_title filter hook is meant to filter the textual content of the title, not to add markup. The template function the_title() is a wrapper around get_the_title(), so it makes sense to place the filter inside the latter.

The the_title function also has "before" and "after" parameters, allowing theme authors to wrap the title in markup.

If there was a the_title_wrap filter, its results would -in many themes - land inside an <h1> element, or even possibly in the header title tag. I don't see a way to add a hook to safely wrap the title in markup, given in how many places the_title() and get_the_title() are potentially used.

As for the_content, that hook filters the post content, which obviously is already a piece of HTML markup that you can safely extend with more markup.

#2 @SergeyBiryukov
5 years ago

  • Component changed from General to Themes
  • Focuses template added
  • Keywords reporter-feedback added

Hi there, thanks for the ticket! How is this different from #39848, though?

#3 @SergeyBiryukov
5 years ago

  • Component changed from Themes to Posts, Post Types
Note: See TracTickets for help on using tickets.