Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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
add comment

Your Answer

 
discard

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.