2013-11-14 49 views
3

即时通讯寻找提高我的页面加载时间/排名和根据PageSpeed Insights ..问题是我的脚本/ css是很多渲染阻止。我怎样才能成功地使用wp_enqueue_script()来帮助我将脚本的大部分放入我的脚本而不是我的标题(wordpress)中。添加JavaScript和CSS到页脚

subject site

CSS例子

<!-- CSS --> 
<link rel="stylesheet" href="<?php echo get_option('siteurl'); ?>/wp-content/themes/<?php echo get_current_theme() ?>/style-jquery-ui-1.8.6.custom.css" type="text/css" /> 
<link rel="stylesheet" href="<?php echo get_option('siteurl'); ?>/wp-content/themes/<?php echo get_current_theme() ?>/style-prettyPhotoCSS.php" type="text/css" /> 

脚本示例

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js?ver=3.7.1'></script> 
+0

改变输出放置在模板(S) – charlietfl

+0

@charlietfl你能解释一下如何做到这一点?我从来没有在 –

+0

之前做过这件事,你实际上想要的是头脑中的css,脚中的js。 – dandavis

回答

1

使用wp_enqueue_script()会是这样的;

add_action('wp_enqueue_scripts','load_scripts'); 
function load_scripts() { 
    wp_enqueue_script('modernizr', get_template_directory_uri() .'/js/modernizr.custom-2.6.2.min.js', array('jquery'), '0.1', true); 
} 

功能场所的最后一个真正的脚本调用页脚

0

http://www.wpbeginner.com/wp-tutorials/how-to-move-javascripts-to-the-bottom-or-footer-in-wordpress/

https://developers.google.com/speed/docs/insights/BlockingJS

http://unserkaiser.com/blog/2013/10/08/how-to-move-wordpress-core-javascript-to-the-footer/

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

使用wp_enqueue_script。

“一旦找到插件或主题,在标题部分添加JavaScript,下一步就是找出插件在哪里调用该文件。在您的主题或插件的PHP文件之一中,您将看到对该特定.js文件的调用

如果插件或主题已在使用队列来添加JavaScript文件,那么您只需更改插件或主题中的wp_register_script函数,并为$ in_footer添加true参数“。