WordPress: Can I use get_template_part in place of get_header, get_footer, etc?

Are there any potential issues with using get_template_part in place of get_header, get_footer, and get_sidebar.

I’d like to keep my theme folder organized and would be nice to move these pieces to the parts directory.

Related posts

Leave a Reply

4 comments

  1. They are required functions. You would actually get errors in a dev enviroment if they are not there. Also those functions are heavilly hooked by other functions and plugins.

  2. If you look at the source for get_header() and get_footer() you can see there isn’t much going on besides calling the hook and loading the include. To preserve the hook and move your header template anywhere you want you could just define a custom get_header() function:

    function custom_get_header($path) {
      do_action('get_header');
      get_template_part($path);
    }
    

    The Sage framework uses this approach for the header and footer, just without the wrapping function. See source.