返回介绍

wp_style_add_data()

发布于 2017-09-11 12:58:22 字数 3289 浏览 1042 评论 0 收藏 0

wp_style_add_data( string $handle,  string $key,  mixed $value )

Add metadata to a CSS stylesheet.


description

Works only if the stylesheet has already been added.

Possible values for $key and $value: ‘conditional’ string Comments for IE 6, lte IE 7 etc. ‘rtl’ bool|string To declare an RTL stylesheet. ‘suffix’ string Optional suffix, used in combination with RTL. ‘alt’ bool For rel="alternate stylesheet". ‘title’ string For preferred/alternate stylesheets.


参数

$handle

(string) (Required) Name of the stylesheet.

$key

(string) (Required) Name of data point for which we're storing a value. Accepts 'conditional', 'rtl' and 'suffix', 'alt' and 'title'.

$value

(mixed) (Required) String containing the CSS data to be added.


返回值

(bool) True on success, false on failure.


源代码

File: wp-includes/functions.wp-styles.php

function wp_style_add_data( $handle, $key, $value ) {
	return wp_styles()->add_data( $handle, $key, $value );
}

更新日志

Versiondescription
3.6.0Introduced.

相关函数

Uses

  • wp-includes/functions.wp-styles.php: wp_styles()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note Contributed by Aamer Shahzad

    Enqueue IE-specific stylesheets with conditional comments

    	
    /**
     * Enqueue styles conditionally using {@see wp_style_add_data()}.
     *
     * Example taken from the Twenty Fifteen theme and is used to load
     * stylesheets specifically for IE8 and below. IE10 and above does
     * not support conditional comments in standards mode.
     *
     * @link     https://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
     * @internal Called from 'wp_enqueue_scripts' action.
     */
    function wpdocs_enqueue_scripts() {
    	// Load the Internet Explorer specific stylesheet.
    	wp_enqueue_style( 'twentyfifteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentyfifteen-style' ), '20141010' );
    	wp_style_add_data( 'twentyfifteen-ie', 'conditional', 'lt IE 9' );
    
    	// Load the Internet Explorer 7 specific stylesheet.
    	wp_enqueue_style( 'twentyfifteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentyfifteen-style' ), '20141010' );
    	wp_style_add_data( 'twentyfifteen-ie7', 'conditional', 'lt IE 8' );
    }
    
    add_action( 'wp_enqueue_scripts', 'wpdocs_enqueue_scripts' );
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文