WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#49496 closed enhancement (duplicate)

filters missing for get_header and get_footer

Reported by: 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 3 months ago.
patch to add update_header_template and update_footer_template
49496.2.diff (770 bytes) - added by sebastienserre 3 months ago.

Download all attachments as: .zip

Change History (5)

@kevdotbadger
3 months ago

patch to add update_header_template and update_footer_template

#1 @kevdotbadger
3 months 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
3 months 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
3 months ago

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

Note: See TracTickets for help on using tickets.