【问题标题】:WordPress: Enqueuing resources - Meaning of the "handle"?WordPress:排队资源 - “句柄”的含义?
【发布时间】:2019-08-11 08:32:55
【问题描述】:

当我在 Wordpress 中将样式或脚本排入队列时,例如:

wp_enqueue_style('style', get_template_directory_uri() . "/style.css");

第一个参数是什么意思?

这里的“风格”...

文档称它为句柄:WordPress - wp_enqueue_style

但我不明白它的目的。文件名在第二个参数中再次重复。

用这个手柄可以做什么?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    句柄是样式表的唯一名称。对于某些 WordPress 样式功能,需要句柄来识别样式表,

    例如使用句柄 wpdocs 注册样式并有条件地将其添加到模板页面

    $handle = 'wpdocs';
    wp_register_style( $handle, get_stylesheet_directory_uri().'/css/mycss.css', array(), '', true );
    
    if ( is_page_template( 'template-name.php' ) ) {
       wp_enqueue_style( $handle );
    }
    

    【讨论】:

    • 非常有意义。 :) 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    相关资源
    最近更新 更多