WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to optimize my header and I was wondering which plugin would call jquery. Is there a debugging tool to know which plugin is doing what in the header ?

Thanks !

share|improve this question
up vote 1 down vote accepted

Plugins and themes tend to use wp_enqueue_script() to queue up scripts for the <head /> of your theme.

I would rarely advise this, but since you only need to do it temporarily, you could modify WordPress core and run a debug backtrace for every call to this function.

In wp-includes/functions.wp-scripts.php, drop the following code inside the end of the wp_enqueue_script() function (starts at line 96).

global $_script_callers_backtrace;
if ( !$_script_callers_backtrace )
    $_script_callers_backtrace = array();

$backtrace = debug_backtrace();
$_script_callers_backtrace[] = array( $handle, $backtrace[0]['file'] );

Now pop the following in your theme's functions.php;

function __save_script_callers()
    file_put_contents( WP_CONTENT_DIR . '/callers.' . date('d-m-Y-H-i-s')  . '.log', print_r( $GLOBALS['_script_callers_backtrace'], true ) ); 
add_action( 'shutdown', '__save_script_callers' );

Now whenever you load a page on your website, a log gets generated in your WordPress wp-content folder that'll contain a list of the script handlers and the files that triggered them.

Remember! Undo the changes once you've found out what you need!

share|improve this answer
Thanks ! I also found out about the wp_enqueue_style function, which allowed me to remove the calls to very small css files. – Jonathan Mar 14 '11 at 10:26

There is a nifty little function called debug_filters() which lists the callbacks registered on a certain hook.

You would call from your theme, at the end of the header.php file for example:

<?php debug_filters('wp_head'); ?>
share|improve this answer
Nice! But surely that's no guarantee it'll show all plugins firing wp_enqueue_script()? Only ones hooked to wp_head? – TheDeadMedic Mar 14 '11 at 10:28
Sure, but it's a starting point. You could also pass 'template_redirect', to catch more. – scribu Mar 14 '11 at 10:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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