Title: Shortcode to output get_header
Last modified: August 21, 2016

---

# Shortcode to output get_header

 *  Resolved [leonardochen0](https://wordpress.org/support/users/leonardochen0/)
 * (@leonardochen0)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/shortcode-to-output-get_header/)
 * I’m trying to create a shortcode that will output the contents of one of my template
   header files.
    I thought I just needed to create it in my functions.php file
 *     ```
       function zoo_header(){
       	return 'test'.get_header('navbar');
       }
       add_shortcode('zoo-header', 'zoo_header');
       ```
   
 * And use it in my templates: [zoo-header] or do_shortcode(‘[zoo-header’])
 * However, the output of the shortcode is simply ‘test’
    Why is the content of 
   my header not showing up?
 * header-navbar.php
 *     ```
       <?php wp_nav_menu( array(
       	'theme_location' => 'right-menu',
       	'container' => false,
       	'menu_id' => 'navbar-right',
       	'menu_class' => 'nav navbar-nav navbar-right'
       )); ?>
       <p>testing 123</p>
       ```
   
 * It’s as if get_header is not returning anything.
    I have 2 headers that I need
   to show, and I wanted to give the template authors the option to choose between
   one or the other.

Viewing 1 replies (of 1 total)

 *  Thread Starter [leonardochen0](https://wordpress.org/support/users/leonardochen0/)
 * (@leonardochen0)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/shortcode-to-output-get_header/#post-4523449)
 * Found the answer.
    The shortcode functions are supposed to return a string, and
   not generate any output. The get_header and get_template_part functions outputs
   their content, so we need to create a buffer.
 * Great article here:
    [http://kovshenin.com/2013/get_template_part-within-shortcodes/](http://kovshenin.com/2013/get_template_part-within-shortcodes/)

Viewing 1 replies (of 1 total)

The topic ‘Shortcode to output get_header’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [leonardochen0](https://wordpress.org/support/users/leonardochen0/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/shortcode-to-output-get_header/#post-4523449)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
