我有以下代码:
function register_scripts(){
wp_register_style( 'new_style', plugins_url('/css/style.css', __FILE__));
wp_register_script( 'google-maps-api', 'http://maps.google.com/maps/api/js?sensor=false' );
}
add_action('wp_enqueue_scripts', 'register_scripts');
但这不起作用,有人能看到我做错了吗?
就像在评论中一样-您已注册它们,但尚未入队...
function regiqueue_scripts(){
wp_register_style( 'new_style', plugins_url('/css/style.css', __FILE__));
wp_register_script( 'google-maps-api', 'http://maps.google.com/maps/api/js?sensor=false' );
wp_enqueue_style( 'new_style' ); // or use just enqueue without register .. but not the other way around
wp_enqueue_script( 'google-maps-api' );
}
add_action('wp_enqueue_scripts', 'regiqueue_scripts');
您会看到-注册脚本只是使它们可供使用,但是直到您告诉脚本后才可以排队。该功能wp_enqueue_xx()
-当所有参数填充时都可以不工作wp_register_xx()
-但反之则不行。
始终使用两者,因为它可以更好地控制在何时何地使用脚本。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句