wp_enqueue_style()
wp_enqueue_style( string $handle, string $src = ”, stri…
wp_enqueue_style( string $handle, string $src = ”, string[] $deps = array(), string|bool|null $ver = false, string $media = ‘all’ )
将CSS样式表排队。
Enqueue a CSS stylesheet.
将CSS样式表排队。
Enqueue a CSS stylesheet.
目录锚点:#说明#参数#源码#笔记
说明(Description)
如果提供了源(不覆盖)则注册样式并排队。另请参阅WP_Dependencies::add()WP_Dependencies::enqueue()
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $handle | (string) | 样式表的名称。应该是独一无二的。 |
| $src | (string) | 样式表的完整URL,或样式表相对于WordPress根目录的路径。 |
| $deps | (string[]) | 注册样式表的数组处理此样式表依赖的。 |
| $ver | (string | bool | null) | 指定样式表版本号(如果有)的字符串,将其作为查询字符串添加到URL中,以用于缓存破坏。如果version设置为false,则会自动添加与当前安装的WordPress版本相同的版本号。如果设置为null,则不添加任何版本。 |
| $media | (string) | 为其定义了此样式表的媒体。接受“全部”、“打印”和“屏幕”等媒体类型,或接受诸如“(方向:纵向)”和“(最大宽度:640px)”等媒体查询。 |
源码(Source)
/**
* Enqueue a CSS stylesheet.
*
* Registers the style if source provided (does NOT overwrite) and enqueues.
*
* @see WP_Dependencies::add(), WP_Dependencies::enqueue()
* @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
*
* @since 2.6.0
*
* @param string $handle Name of the stylesheet.
* @param string|bool $src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'.
* @param array $deps An array of registered style handles this stylesheet depends on. Default empty array.
* @param string|bool $ver String specifying the stylesheet version number, if it has one. This parameter is used
* to ensure that the correct version is sent to the client regardless of caching, and so
* should be included if a version number is available and makes sense for the stylesheet.
* @param string $media Optional. The media for which this stylesheet has been defined.
* Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
* 'screen', 'tty', or 'tv'.
*/
function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
$wp_styles = wp_styles();
if ( $src ) {
$_handle = explode('?', $handle);
$wp_styles->add( $_handle[0], $src, $deps, $ver, $media );
}
$wp_styles->enqueue( $handle );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.6.0 | wp-includes/functions.wp-styles.php | 19 | 5 |
笔记(Notes)
用钩子
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!