How to handle with WordPress scripts actions mess?

During developing WordPress + BuddyPress child theme I came across the problem with scripts.
I want to move them to BODY footer (except Modernizr), but some BuddyPress script stay on the top. I heve made it:

// remove unused head entries
remove_action('wp_head',        'rsd_link');
//...
remove_action('wp_head',        'adjacent_posts_rel_link');

// move sctipts to footer
remove_action('wp_head',        'wp_print_scripts');
remove_action('wp_head',        'wp_print_head_scripts');
remove_action('wp_head',        'wp_enqueue_scripts');
remove_action('wp_head',        'bp_core_confirmation_js');
remove_action('wp_head',        'bp_core_add_ajax_url_js');

add_action('wp_head',           'wp_head_scripts',      9);
add_action('wp_footer',         'wp_enqueue_scripts',           20);
add_action('wp_footer',         'bp_core_confirmation_js',      21);
add_action('wp_footer',         'bp_core_add_ajax_url_js',      22);

I’m confused with action order and it doesn’t look pretty.

Read More

Is it possible to make it prettier (more automatic)? I thinking about an array like this:

$head_scripts = array(
    'modernizr'         => 'libs/modernizr-2.6.1.js',
);
$footer_scripts = array(
    'jquery'            => 'libs/jquery-1.8.2.js',
    'jquery.mansonry'   => 'libs/jquery.masonry.min.js',
    'fb_api'            => 'libs/fb_api.js',
    'scripts'           => 'script.js'
);

and one function (action), which add first in the head, other in the footer and next admin_bar, buddypress scripts if necessary.

Related posts

Leave a Reply

1 comment

  1. Why dont you track all those script wp_enqueue_script file and change the in_footer parameter to true. As you may know that the wp_enqueue_script method has the last parameter which you can indicate whether that script will be placed into the footer. The default is false which will be put into the header

     wp_enqueue_script( 
            $handle
           ,$src
           ,$deps
           ,$ver
           ,$in_footer  // make this TRUE to put the script in the footer
    );
    

    For more info visit the doc http://codex.wordpress.org/Function_Reference/wp_enqueue_script