Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#37302 closed enhancement (duplicate)

get_header(), get_sidebar() and get_footer() doesn't use template_include()

Reported by: schoenwaldnils's profile schoenwaldnils Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.5.3
Component: General Keywords:
Focuses: template Cc:



I'm building a plugin for using haml in themes, where I have to get every template before it is included.

I tried to add an action using add_action( 'template_include', 'my_function');
This hook did pretty well, except for the header, sidebar, and footer.

I also tried to use get_included_files() like @nacin mentioned here:
The problem there is, that I only get the files after they are included.

Is it possible that get_header(), get_sidebar() and get_footer() can use template_include()?

Change History (1)

#1 @DrewAPicture
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi @schoenwaldnils, welcome to Trac!

There's a lot of history for why including or requiring templates work the way they do in the WordPress template loader.

A lot of it has to do with whether or not they should be loaded in global scope and introduce global variables across templates. I would really suggest reading up on #18265 where the template_include filter was introduced, though it's kind of the reverse situation.

The basic gist is that files loaded via get_header|sidebar|footer() deliberately load global scope and files brought in through the template loader don't. In short: roping these functions into template_include would be an end-run around how template loading is intended to work within that scope.

All of that said, since the ultimate goal is to have some measure of control over what's loading when, I'm closing this as a duplicate #13239, and encourage you to focus your attention there. locate_template() is the key.

Note: See TracTickets for help on using tickets.