我正在尝试优化我公司的网站,现在我正在尝试让wordpress在页脚而不是网页顶部加载所有的javascript,以使其更快地加载网站。我将以下代码添加到function.php文件中:
// super easy way to move javascript to footer
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5); 问题是,我使用的是一个内置在javascript中的滑块插件,但在这段代码中它消失了。
有谁知道我怎样才能从我的wordpress页面的页脚加载所有的javascript和jquery,并且滑块不会消失?
网站url为www.contidosdixitais.com
非常感谢
发布于 2015-02-06 18:02:26
也许下面的代码可以做到这一点:
// The callback function for the action hook bellow
function any_script_in_footer()
{
// Call the list with all the registered scripts
global $wp_scripts;
if ( isset ( $wp_scripts->registered ) && ! empty ( $wp_scripts->registered ) && is_array( $wp_scripts->registered ) ) {
foreach ( $wp_scripts->registered as $idx => $script ) {
if ( isset( $wp_scripts->registered[ $idx ]->extra ) && is_array( $wp_scripts->registered[ $idx ]->extra ) ) {
// Set any of the scripts to belong in the footer group
$wp_scripts->registered[ $idx ]->extra[ 'group' ] = 1;
}
}
}
}
// Call the callback function with the `wp_print_scripts` hook at the very end
// of the callbacks cue
add_action('wp_print_scripts', 'any_script_in_footer', 1000);https://stackoverflow.com/questions/28362862
复制相似问题