检查脚本/样式是否已入队/注册

时间:2011-03-03 作者:kaiser

是否可以使用wp_register_script/_stylewp_enqueue_script/_style? 所有函数都不会返回值,我完全不知道。

我需要它根据我提供的样式表库和脚本在不同的函数之间切换。

非常感谢。

2 个回复
最合适的回答,由SO网友:Annika Backstrom 整理而成

有一个函数称为wp_script_is( $handle, $list ). $list 可以是以下内容之一:

已通过注册wp_register_script()wp_enqueue_script()

  • \'done\'(已打印)
  • \'to\\u do\'(待打印)
  • 同上wp_style_is().

    SO网友:fuxia

    检查$GLOBALS[\'wp_scripts\']->registered 用于脚本。

    Example

    function is_enqueued_script( $script )
    {
        return isset( $GLOBALS[\'wp_scripts\']->registered[ $script ] );
    }
    
    print (int) is_enqueued_script( \'l10n\' );
    
    $GLOBALS[\'wp_styles\']->registered 工作方式相同。

    结束

    相关推荐