Title: Replace get_header() or header.php via plugin
Last modified: August 30, 2016

---

# Replace get_header() or header.php via plugin

 *  [Gloria](https://wordpress.org/support/users/erfo/)
 * (@erfo)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/replace-get_header-or-headerphp-with-plugin/)
 * How can I replace get_header function or header.php via plugin?
 * I installed a child theme and now I’d like to add an html code into header.php
 * I used this:
 *     ```
       function myheader( $template ) {
           if ( locate_template( 'header.php' ) != '' ) {
               return untrailingslashit( plugin_dir_path( __FILE__ ) ) . 'header.php';
           }
       	return $template;
       }
       add_filter( 'template_include', 'myheader', 11 );
       ```
   
 * It replaces the header and shows only the header and not the full template (the
   content, sidebar, footer…)

Viewing 1 replies (of 1 total)

 *  [jramoscarmenates](https://wordpress.org/support/users/jramoscarmenates/)
 * (@jramoscarmenates)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/replace-get_header-or-headerphp-with-plugin/#post-8214260)
 * The next solution don’t like me but is an options:
 * Go to ‘wp-includes/general-template.php’ file and add:
 * $templates = apply_filters(‘replace_header’, $templates);
    In the get_header 
   function the final result function is:
 *     ```
       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 $name Name of the specific header file to use.
            */
           do_action( 'get_header', $name );
   
           $templates = array();
           $name = (string) $name;
           if ( '' !== $name ) {
               $templates[] = "header-{$name}.php";
           }
   
           $templates[] = 'header.php';
   
           $templates = apply_filters('replace_header', $templates); //This is the new line.
   
           locate_template( $templates, true );
       }
       ```
   
 * And before that you can:
 *     ```
       function prefix_new_header() {
           return 'header-newtmpl.php';
       }
       add_filter( 'get_header', 'prefix_new_header' );
       ```
   
 * I never modify the source code, I only put here one solution to the problem.
 * Original Source: [http://stackoverflow.com/questions/39661295/get-header-action-not-working/39662513#39662513](http://stackoverflow.com/questions/39661295/get-header-action-not-working/39662513#39662513)
 * Jose Carlos Ramos Carmenates
    -  This reply was modified 9 years, 8 months ago by [jramoscarmenates](https://wordpress.org/support/users/jramoscarmenates/).

Viewing 1 replies (of 1 total)

The topic ‘Replace get_header() or header.php via plugin’ is closed to new replies.

## Tags

 * [child theme](https://wordpress.org/support/topic-tag/child-theme/)
 * [get_header](https://wordpress.org/support/topic-tag/get_header/)
 * [header.php](https://wordpress.org/support/topic-tag/header-php/)
 * [template_include](https://wordpress.org/support/topic-tag/template_include/)

 * 1 reply
 * 2 participants
 * Last reply from: [jramoscarmenates](https://wordpress.org/support/users/jramoscarmenates/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/replace-get_header-or-headerphp-with-plugin/#post-8214260)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
