- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
関数リファレンス/wp register style
提供: WordPress Codex 日本語版
このページ「関数リファレンス/wp register style」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています。
目次
説明
後で wp_enqueue_style() に渡すために、CSS スタイルファイルを安全に登録します。
使い方
<?php wp_register_style( $handle, $src, $deps, $ver, $media ); ?>
重要: アクション wp_enqueue_scripts
/en を使ってこの関数を呼び出してください。 アクションではないところから呼び出すと問題を引き起こす場合があります。詳しくは Trac チケット #17916 を見てください。
パラメータ
- $handle
- (string) (必須) Name of the stylesheet (which should be unique as it is used to identify the script in the whole system).
- 初期値: なし
- $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'.
- 初期値: なし
- $deps
- (array) (optional) Array of handles of any stylesheets that this stylesheet depends on. Dependent stylesheets will be loaded before this stylesheet.
- 初期値: array()
- $ver
- (string|boolean) (optional) 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) (optional) 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'
Return Values
- (bool)
- Whether the style has been registered. True on success, false on failure.
Examples
In a Plugin (outside a PHP class)
// Register style sheet. add_action( 'wp_enqueue_scripts', 'register_plugin_styles' ); /** * Register style sheet. */ function register_plugin_styles() { wp_register_style( 'my-plugin', plugins_url( 'my-plugin/css/plugin.css' ) ); wp_enqueue_style( 'my-plugin' ); }
- Assumes the Plugin directory is named 'my-plugin'.
- Assumes the Plugin style sheet is named 'plugin.css'.
In a Plugin (inside a PHP class)
class my_plugin { /** * @TODO Add class constructor description. */ function __construct() { // Register style sheet. add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_styles' ) ); } /** * Register and enqueue style sheet. */ public function register_plugin_styles() { wp_register_style( 'my-plugin', plugins_url( 'my-plugin/css/plugin.css' ) ); wp_enqueue_style( 'my-plugin' ); } }
- 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'.
Notes
- Uses global: (WP_Styles /en object) $wp_styles
- See wp_default_styles() in
wp-includes/script-loader.php
for a complete list of styles WordPress registers by default.
Change Log
- Since: 2.1 (BackPress version: r79)
Source File
wp_register_style() is located in wp-includes/functions.wp-styles.php
.
Resources
Related
- エンキュー関数:
- スクリプト:wp_register_script(),wp_deregister_script(), wp_enqueue_script(), wp_dequeue_script() /en, wp_script_is() /en, wp_localize_script(), wp_enqueue_media()
- スタイル: wp_register_style(),wp_deregister_style() /en,wp_enqueue_style(),wp_dequeue_style(), wp_style_is() /en
- エンキューアクション:
- フロントエンド: wp_enqueue_scripts /en, wp_print_scripts /en, wp_print_styles /en
- 管理画面: admin_enqueue_scripts /en, admin_print_scripts / en, admin_print_styles /en
- ログイン: login_enqueue_scripts /en
関数リファレンス、テンプレートタグ目次もご覧ください。
最新英語版: WordPress Codex » Function Reference/wp register style (最新版との差分)