I am using the template_redirect action to redirect a user to a custom template which has no header, sidebar or footer (the intent is for it to be in an iframe as a dialog box). After I done the redirect though, I could not seem to get all the enqueued JS and CSS to list.

Here's the code:

     * This theme file is accessed by template redirect
     * No header, sidebar or footer

    <!DOCTYPE html>
    <title>Customize Product</title>

    <?php wp_head()?>
    <div id="container">
                <div id="content" role="main">

                 * Output the content of the template 

                </div><!-- #content -->
            </div><!-- #container -->


Edit: Here's how I am including the JS

// bootstrap code, will refactor later as necessary
if (is_admin())
    global $admin_class;
    $admin_class = new product_customize_admin();

    add_action('admin_menu', 'init_admin_menu');
    add_action('admin_print_scripts', 'my_admin_scripts');
    add_action('admin_print_styles', 'my_admin_styles');

    add_action('wp_head', 'include_frontend_scripts');

    // setup frontend
    global $frontend_class;
    $frontend_class = new product_customize();


function include_frontend_scripts()

    // preset scripts
    wp_register_script('product-customize-preset', plugin_dir_url(__FILE__).'js/preset.js');

Here's the code for the template redirect

function theme_redirect()
    global $wp;
    $plugin_dir = dirname(__FILE__);

    //echo '<pre>'.print_r($_GET, true).'</pre>';

    // if we are doing product customization
    if ($_GET['prod_cust_do_customize'] == 1)
        $return_template = $plugin_dir.'/themefiles/customize_preset_page.php';
        echo "template = $return_template";



function do_theme_redirect($url)
    include ($url);
  • 1
    scripts should be enqueued on the wp_enqueue_scripts action, not wp_head – Milo Sep 25 '12 at 4:53

If CSS is not outputting inside wp_head, it may imply that they're not being enqueued correctly. See here for more info. Maybe they're hardcoded in the theme file? In header.php?

As for scripts, my guess is that they are being enqueued and set to trigger during footer actions, so the fact that you're not calling wp_footer() means that those actions never fire.

If you cannot edit the footer.php template file to remove all the unnecessary output, while still leaving wp_footer() the code above, then at least trigger the usual actions manually, like so:

// ...
        </div><!-- #content -->
    </div><!-- #container -->

<?php do_action('wp_print_footer_scripts'); ?>


It's hard to tell if this will work, because it can depend on how the scripts are enqueued, and it varies wildly from plugin to plugin (especially if the original coder doesn't follow WP coding standards), but hopefully it'll lead you in the right direction.


If you need to add dependencies to your scripts, like jQuery, to make sure those deps are enqueued and loaded before your own, do this:

wp_register_script('product-customize-preset', plugin_dir_url(__FILE__).'js/preset.js', array('jquery'));
  • The missing script files are added via a plugin which add it using a add_action('wp_head', 'include_js'). Normally the js shows up, but not after a template redirect. – Extrakun Sep 24 '12 at 4:21
  • Could you paste the include_js function? Also, can you post the template_redirect action code? If everything is supposed to be in the header, then the problem may be somewhere else and not on the code you posted above. – Tomas Buteler Sep 24 '12 at 11:07
  • It works if I use do_action("wp_enqueue_scripts", 'include_frontend_scripts') but my scripts are included before jQuery, so it wouldn't work for me. – Extrakun Sep 25 '12 at 4:38
  • That can be easily fixed. See edited answer. On a side note, are you using the 'template_redirect' action at all? – Tomas Buteler Sep 25 '12 at 11:50
  • Yes, I am using template_redirect action. add_action('template_redirect', 'theme_redirect') – Extrakun Sep 25 '12 at 14:24

Make sure you have wp_footer() added to your footer.php file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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