[wp-trac] [WordPress Trac] #40508: Add new do_action after load template files

WordPress Trac noreply at wordpress.org
Tue May 30 20:04:31 UTC 2017


#40508: Add new do_action after load template files
-------------------------------------------+------------------------------
 Reporter:  rajanit2000                    |       Owner:
     Type:  enhancement                    |      Status:  new
 Priority:  normal                         |   Milestone:  Awaiting Review
Component:  Themes                         |     Version:
 Severity:  normal                         |  Resolution:
 Keywords:  needs-patch reporter-feedback  |     Focuses:  template
-------------------------------------------+------------------------------

Old description:

> Could not perform action after get_header loads.
>
> get_header hook only perform before template part loads. So we can add
> new do_action after template files  loads
>
> '''
> do_action( 'get_header_after', $name );'''
>

> {{{
> function get_header( $name = null ) {
>         /**
>          * Fires before the header template file is loaded.
>          *
>          * The hook allows a specific header template file to be used in
> place of the
>          * default header template file. If your file is called header-
> new.php,
>          * you would specify the filename in the hook as get_header(
> 'new' ).
>          *
>          * @since 2.1.0
>          * @since 2.8.0 $name parameter added.
>          *
>          * @param string|null $name Name of the specific header file to
> use. null for the default header.
>          */
>         do_action( 'get_header', $name );
>
>         $templates = array();
>         $name = (string) $name;
>         if ( '' !== $name ) {
>                 $templates[] = "header-{$name}.php";
>         }
>
>         $templates[] = 'header.php';
>
>         locate_template( $templates, true );
>
>         do_action( 'get_header_after', $name );
> }
> }}}

New description:

 Could not perform action after get_header loads.

 get_header hook only perform before template part loads. So we can add new
 do_action after template files  loads

 '''
 do_action( 'get_header_after', $name );'''


 {{{
 function get_header( $name = null ) {
         /**
          * Fires before the header template file is loaded.
          *
          * The hook allows a specific header template file to be used in
 place of the
          * default header template file. If your file is called header-
 new.php,
          * you would specify the filename in the hook as get_header( 'new'
 ).
          *
          * @since 2.1.0
          * @since 2.8.0 $name parameter added.
          *
          * @param string|null $name Name of the specific header file to
 use. null for the default header.
          */
         do_action( 'get_header', $name );

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

         $templates[] = 'header.php';

         locate_template( $templates, true );

         do_action( 'get_header_after', $name );
 }
 }}}

 I'll get a patch made soon.

--

Comment (by desrosj):

 This would be very helpful.

 I have a child theme that uses a framework. Currently, the only way to
 include the additional markup that I need would be to override the file in
 the `header.php` child theme.

 Ideally, I would like to add a function to an action hook to include this
 additional markup to prevent overriding the entire template file.

 {{{
 function my_additional_markup( $template_slug ) {
     ?>
     <div>my additional stuff</div>
     <?php
     // Could also include a template part
     if ( 'additional-header-type' === $slug ) {
         get_template_part( 'additional_template', 'slug' );
     }
 }
 add_action( 'after_get_header', 'my_additional_markup' );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40508#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list