Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#49496 closed enhancement (duplicate)

filters missing for get_header and get_footer

Reported by: kevdotbadger's profile kevdotbadger Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.4
Component: Themes Keywords: has-patch
Focuses: template Cc:

Description

Seems like a minor thing that has quite a big impact. The preferred way to load different headers and footers is to use the $name argument in get_header() and get_footer().

This works fine. However, modifying them from a plugin, or even from a theme when logic decides which is loaded makes them get messy quite quickly.

A solution (which I've used), is to set the $name argument to a 'global' variable in my functions.php file and then use that thoughout my theme. When I need to conditionally set the header/footer I simply update that variable.

Surely a filter for both get_header() and get_footer(), would be a better solution?

Attachments (2)

49496.diff (643 bytes) - added by kevdotbadger 5 years ago.
patch to add update_header_template and update_footer_template
49496.2.diff (770 bytes) - added by sebastienserre 5 years ago.

Download all attachments as: .zip

Change History (5)

@kevdotbadger
5 years ago

patch to add update_header_template and update_footer_template

#1 @kevdotbadger
5 years ago

  • Keywords has-patch added

I've just added a patch which adds the functionality, but could do with looking over.

The get_header() and get_footer() functions seems to work as arrays, and uses the first item in the array as the actual file to load. I guess the others are fallbacks? So, using the filter will require you to add your additional template as the first item (using array_unshift).

Could possibly rewrite this, and do that inside the actual get_header (or get_header)?

#2 @ocean90
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hello @kevdotbadger, thanks for the ticket and the patch.

We're already tracking this issue in #13239 and #42855.

#3 @kevdotbadger
5 years ago

@ocean90 This is being tracked in a 10 year old ticket. You being serious?

Note: See TracTickets for help on using tickets.