[wp-trac] [WordPress Trac] #51726: proposal: make specialized header name available inside header.php

WordPress Trac noreply at wordpress.org
Sat Nov 7 15:23:26 UTC 2020


#51726: proposal: make specialized header name available inside header.php
-------------------------+-----------------------------
 Reporter:  Jules Colle  |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Themes       |    Version:  5.5.2
 Severity:  normal       |   Keywords:  needs-patch
  Focuses:               |
-------------------------+-----------------------------
 You can call `get_header()` with an extra argument. For example:
 `get_header('wp-signup')`. This allows theme authors to create a specific
 header: `header-wp-signup.php`.

 But it would be nice to also this name inside the regular `header.php`
 file, to allow for a small tweak instead of completely duplicating the
 header.php file.

 My proposal is to modify this function in `wp-includes/general-
 template.php` line 27:

 {{{#!php
 <?php
 function get_header( $name = null, $args = array() ) {
         /**
          * Fires before the header template file is loaded.
          *
          * @since 2.1.0
          * @since 2.8.0 The `$name` parameter was added.
          * @since 5.5.0 The `$args` parameter was added.
          *
          * @param string|null $name Name of the specific header file to
 use. Null for the default header.
          * @param array       $args Additional arguments passed to the
 header template.
          */
         do_action( 'get_header', $name, $args );

         $templates = array();
         $name      = (string) $name;
         if ( '' !== $name ) {
                 $templates[] = "header-{$name}.php";
         }

         $templates[] = 'header.php';

         if ( ! locate_template( $templates, true, true, $args ) ) {
                 return false;
         }
 }
 }}}


 We could call `locate_template` like this:

 {{{#!php
 <?php
 locate_template( $templates, true, true, array_merge($args,[ '__name' =>
 $name ]) )
 }}}

 Then, inside `header.php` it would be possible to access the header name
 like this:

 `$header_name = $args['__name']`

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51726>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list