1

Wordpress + BuddyPress 子テーマの開発中に、スクリプトの問題に遭遇しました。それらを BODY フッター (Modernizr を除く) に移動したいのですが、一部の BuddyPress スクリプトが上部に残ります。私はそれを作った:

// 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);

アクションの順序が混乱していて、きれいに見えません。

よりきれいにする(より自動化する)ことは可能ですか?私はこのような配列について考えています:

$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'
);

1 つの関数 (アクション) は、最初に head に追加され、その他はフッターに追加され、次の admin_bar、必要に応じて buddypress スクリプトが追加されます。

4

1 に答える 1

0

これらすべてのスクリプトwp_enqueue_scriptファイルを追跡し、in_footerパラメータをtrueに変更しないのはなぜですか。ご存知かもしれませんが、wp_enqueue_scriptメソッドには、そのスクリプトをフッターに配置するかどうかを示すことができる最後のパラメーターがあります。デフォルトはfalseで、ヘッダーに配置されます

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

詳細については、ドキュメントhttp://codex.wordpress.org/Function_Reference/wp_enqueue_scriptをご覧ください。

于 2012-11-17T05:04:22.037 に答える