首页 > 解决方案 > 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');

两者的工作方式相同。但我看到许多专家以这两种不同的方式做事。

标签: javascriptphpcss

解决方案


wp_register_style :-

这意味着,如果您想注册您的脚本,但不直接将它们加载到您的页面中,您可以注册一次文件,然后在需要时加载它们。

wp_enque_style :- 它可以帮助您加载脚本


推荐阅读