javascript - ENQUEUE 脚本直接而不是先注册
问题描述
注册样式表然后将其入队与直接入队有何不同?
在这里我注册然后排队。
function calling_script(){
wp_register_style('bootstrap', get_template_uri(). `enter code here`'/css/bootstrap.min.css',array(),'1.0.0', 'all');
wp_enqueue_style('bootstrap');
wp_register_style('style', get_template_uri(). '/css/style.css',array(),'1.0.0', 'all');
wp_enqueue_style('style');
}
add_action('wp_enqueue_style','calling_script');
这里我直接入队:
function calling_resources(){
//Calling Styles
wp_enqueue_style('style',get_stylesheet_uri(),'','1.0.0');
wp_enqueue_style('comment_style',get_template_directory_uri().'/css/comments.css','','1.0.0');
wp_enqueue_style('404 style',get_template_directory_uri().'/css/style-404.css','','1.0.0');
}
add_action('wp_enqueue_scripts','calling_resources');
两者的工作方式相同。但我看到许多专家以这两种不同的方式做事。
解决方案
wp_register_style :-
这意味着,如果您想注册您的脚本,但不直接将它们加载到您的页面中,您可以注册一次文件,然后在需要时加载它们。
wp_enque_style :- 它可以帮助您加载脚本
推荐阅读
- excel - VBA 宏可在不同工作表中创建不同范围的单个 pdf
- sql - 使用 VBA for Excel:从 ODBC SQL 中提取数据,如何使用“今天前一年”的值?
- c# - 在 VS2017/2019 中构建 StackOverflowException
- javascript - 将 Vue.JS 项目转换为 Nuxt.JS 项目
- mysql - 永久阻止 mariadb
- .net - 允许从 v4.8 降级到 v4.5.1
- javascript - 元素在 Chrome 77 上短暂消失并重新出现
- r - 自动将工作目录设置为 R 中当前打开的文件夹
- java - 如何在 EditText 中进行正常的行编号?
- twilio - Autopilot 的收集功能无法处理重音