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!