So the reason why I am don't want to include get_header() or get_footer() tags is because this page will be loaded as an iframe using the thickbox modal plugin and its content will be a form and I don't want the aforementioned tags to render all the menus and banner images and menus as well as the footer content because it will make for lots of scrolling on this page.

However, current I'm running something like this:

add_action('template_redirect', 'my_plugin_add_js');

However, when I take out the get_header() and get_footer() tags then the JavaScript doesn't load even though the javascripts inside the 'my_plugin_add_js' are being added within the body HTML tags at the end and not inside the head tags, like so:

wp_register_script("validate_form", plugins_url('js/my_plugin_validate_form.js', __FILE__), array('jquery', 'validation'), '1.0', true);

So I gather that the 'template_redirect' action hook is not the right one to use.


3 Answers 3


Completely skipping wp_head and wp_footer doesn't seem like a good idea, many core components and plugins depend on these hooks. Instead, you could create a light header and footer, and load them via an extra argument to get_header() and get_footer(). get_header( 'light' ) will load header-light.php instead of the regular header file. Create one without the visual header of the other pages, but leave the wp_head action intact.

  • Hmm, interesting. I didn't know I could load other header templates through a function parameter. I'm fairly new to this theme and plugin development and this will be handy. Alternatively I thought about accomplishing through a custom hook that calls up another header template, a light one, like you suggested but, again, I didn't know it could be as easy peasy as passing an argument to the get_header, get_footer functions. Thanks, this helps and solves my dilemma.
    – racl101
    Apr 21, 2011 at 17:56

It's not about hook you use to set up queue (although you should use wp_enqueue_scripts instead but what you are doing will break that as well), it's that by removing header and footer you are also removing wp_head and wp_footer hooks that (among many other things) handle output of queued scripts.

If your template is that minimal it is probably easiest to explicitly echo your script with wp_print_scripts() (pass your script's handle).


Have you considered using a Conditional Tag?

For example:

<?php if(is_page('your-page-name')) { ?>
//inlcude script here
<?php } ?>

More on Conditional Statements: http://codex.wordpress.org/Conditional_Tags

  • I initially thought to do that but I thought that there had to be a better way to do it. Thanks for the suggestion nevertheless.
    – racl101
    Apr 21, 2011 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.