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 !

2 Answers 2


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!

  • 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, 2011 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'); ?>
  • Nice! But surely that's no guarantee it'll show all plugins firing wp_enqueue_script()? Only ones hooked to wp_head? Mar 14, 2011 at 10:28
  • Sure, but it's a starting point. You could also pass 'template_redirect', to catch more.
    – scribu
    Mar 14, 2011 at 10:56

Your Answer

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

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