wp_register_style()
wp_register_style( string $handle, string|bool $src, string[] $deps = array(), string|bool|null $ver = false, string $media = ‘all’ )
注册CSS样式表。
Register a CSS stylesheet.
说明(Description)
另请参见#另请参阅WP_Dependencies::add()
参数(Parameters)
参数 | 类型 | 说明 |
---|---|---|
$handle | (string) | 样式表的名称。应该是独一无二的。 |
$src | (string | bool) | 样式表的完整URL,或样式表相对于WordPress根目录的路径。如果source设置为false,则样式表是它所依赖的其他样式表的别名。 |
$deps | (string[]) | 注册样式表的数组处理此样式表依赖的。 |
$ver | (string | bool | null) | 指定样式表版本号(如果有)的字符串,将其作为查询字符串添加到URL中,以用于缓存破坏。如果version设置为false,则会自动添加与当前安装的WordPress版本相同的版本号。如果设置为null,则不添加任何版本。 |
$media | (string) | 为其定义了此样式表的媒体。接受“全部”、“打印”和“屏幕”等媒体类型,或接受诸如“(方向:纵向)”和“(最大宽度:640px)”等媒体查询。 |
源码(Source)
/** * Register a CSS stylesheet. * * @see WP_Dependencies::add() * @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types. * * @since 2.6.0 * @since 4.3.0 A return value was added. * * @param string $handle Name of the stylesheet. * @param string|bool $src Path to the stylesheet from the WordPress root directory. 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. Used to ensure that the correct version * is sent to the client regardless of caching. Default 'false'. Accepts 'false', 'null', or 'string'. * @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'. * @return bool Whether the style has been registered. True on success, false on failure. */ function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); return wp_styles()->add( $handle, $src, $deps, $ver, $media ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
4.3.0 | wp-includes/functions.wp-styles.php | 16 | 18 |
笔记(Notes)
示例
wp_register_style() 为WP2原创文章,链接:https://www.wp2.cn/functions/wp_register_style/