wp_register_style()注册一个样式表

目录

描述

A safe way to register a CSS style file for later use with wp_enqueue_style().

wp_register_style() 描述

用法

<?php wp_register_style$handle$src$deps$ver$media ); ?>Use the wp_enqueue_scripts action to call this function. Calling it outside of an action can lead to problems. See #17916 for details.

wp_register_style() 用法

参数

$handle

(string) (必填) Name of the stylesheet (which should be unique as it is used to identify the script in the whole system).

默认值: None

$src

(string) (必填) URL to the stylesheet. Example: 'http://example.com/css/mystyle.css'. You should never hardcode URLs to local styles, use plugins_url()(for Plugins) and get_template_directory_uri() (for Themes) to get a proper URL. Remote assets can be specified with a protocol-agnostic URL, i.e. '//otherdomain.com/css/theirstyle.css'.

默认值: None

$deps

(array) (可选) Array of handles of any stylesheets that this stylesheet depends on. Dependent stylesheets will be loaded before this stylesheet.

默认值: array()

$ver

(string|boolean) (可选) 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. The version is appended to the stylesheet URL as a query string, such as ?ver=3.5.1. By default, or if false, the WordPress version string is used. If null nothing is appended to the URL.

默认值: false

$media

(string) (可选) String specifying the media for which this stylesheet has been defined. Examples: 'all', 'screen', 'handheld', 'print'. See this list for the full range of valid CSS-media-types.

默认值: 'all'

wp_register_style() 参数

返回值

(void) 

This function does not return a value.

wp_register_style() 返回值

示例

In a Plugin (outside a PHP class)

  • Assumes the Plugin directory is named 'my-plugin'.
  • Assumes the Plugin style sheet is named 'plugin.css'.

In a Plugin (inside a PHP class)

  • Assumes the Plugin class name is 'my_plugin'.
  • Assumes the Plugin directory is named 'my-plugin'.
  • Assumes the Plugin style sheet is named 'plugin.css'.

wp_register_style() 示例

注意

wp_register_style() 注意

历史

  • 添加于 版本: 2.1 (BackPress version: r79)

wp_register_style() 历史

源文件

wp_register_style() 函数的代码位于 wp-includes/functions.wp-styles.php.

wp_register_style() 源文件

相关