使用该函数使外部脚本入队是否正确?它可以工作,但是打开网站的速度不慢吗?
wp_register_script( 'google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=true', null, null, true );
wp_register_script( 'jsapi', 'https://www.google.com/jsapi', null, null, true );
wp_register_script( 'bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', null, null, true );
wp_register_script( 'unveil', get_template_directory_uri() . '/new-js/jquery.unveil.min.js', null, null, true );
Run Code Online (Sandbox Code Playgroud)
不,它不会降低网站速度(至少不足以使其成为不使用它的原因)。这是在WordPress中排队任何类型的脚本的正确方法。此功能所做的全部工作就是将适当的<link>标签(带有依赖项)添加到HTML中<head>。
但是,由于某种原因,您没有在代码中包含依赖项。例如,Bootstrap需要jQuery,因此您应该在函数中包括它:
wp_enqueue_script( 'bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array('jquery'), '3.3.5', true );
Run Code Online (Sandbox Code Playgroud)
如上所示,您还应该考虑使用wp_enqueue_script()而不是wp_register_script(),因为这样可以节省您一步。
| 归档时间: |
|
| 查看次数: |
3616 次 |
| 最近记录: |