wp_admin_css

函式
wp_admin_css ( $file = 'wp-admin', $force_echo = false )
引數
  • (string) $file Optional. Style handle name or file name (without ".css" extension) relative to wp-admin/. Defaults to 'wp-admin'.
    Required:
    Default: 'wp-admin'
  • (bool) $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
    Required:
    Default: false
定義位置
相關方法
wp_admin_css_uriwp_admin_css_colorwp_admin_headersprint_admin_styleswp_doing_cron
引入
2.3.0
棄用
-

wp_admin_css: 這是一個WordPress的函式,可以在頁面上新增一個管理員的CSS樣式表。它把指定的CSS檔案排到WordPress的管理區。

列隊或直接列印一個樣式錶連結到指定的CSS檔案。

“智慧”地決定排隊或列印CSS檔案。如果{@see ‘wp_print_styles’}動作*還沒有被呼叫,CSS檔案將被排隊。如果{@see ‘wp_print_styles’}動作已經被呼叫,CSS連結將被列印。可以通過傳遞true作為$force_echo(第二)引數來強制列印。

為了向後相容WordPress 2.3的呼叫方法。如果$file(第一個)引數沒有對應於一個已註冊的CSS檔案,我們假定$file是一個相對於wp-admin/的檔案,沒有”.css”副檔名。一個生成的URL的樣式錶連結會被列印出來。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
// For backward compatibility.
$handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
if ( wp_styles()->query( $handle ) ) {
if ( $force_echo || did_action( 'wp_print_styles' ) ) {
// We already printed the style queue. Print this one immediately.
wp_print_styles( $handle );
} else {
// Add to style queue.
wp_enqueue_style( $handle );
}
return;
}
$stylesheet_link = sprintf(
"<link rel='stylesheet' href='%s' type='text/css' />n",
esc_url( wp_admin_css_uri( $file ) )
);
/**
* Filters the stylesheet link to the specified CSS file.
*
* If the site is set to display right-to-left, the RTL stylesheet link
* will be used instead.
*
* @since 2.3.0
* @param string $stylesheet_link HTML link element for the stylesheet.
* @param string $file Style handle name or filename (without ".css" extension)
* relative to wp-admin/. Defaults to 'wp-admin'.
*/
echo apply_filters( 'wp_admin_css', $stylesheet_link, $file );
if ( function_exists( 'is_rtl' ) && is_rtl() ) {
$rtl_stylesheet_link = sprintf(
"<link rel='stylesheet' href='%s' type='text/css' />n",
esc_url( wp_admin_css_uri( "$file-rtl" ) )
);
/** This filter is documented in wp-includes/general-template.php */
echo apply_filters( 'wp_admin_css', $rtl_stylesheet_link, "$file-rtl" );
}
}
function wp_admin_css( $file = 'wp-admin', $force_echo = false ) { // For backward compatibility. $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file; if ( wp_styles()->query( $handle ) ) { if ( $force_echo || did_action( 'wp_print_styles' ) ) { // We already printed the style queue. Print this one immediately. wp_print_styles( $handle ); } else { // Add to style queue. wp_enqueue_style( $handle ); } return; } $stylesheet_link = sprintf( "<link rel='stylesheet' href='%s' type='text/css' />n", esc_url( wp_admin_css_uri( $file ) ) ); /** * Filters the stylesheet link to the specified CSS file. * * If the site is set to display right-to-left, the RTL stylesheet link * will be used instead. * * @since 2.3.0 * @param string $stylesheet_link HTML link element for the stylesheet. * @param string $file Style handle name or filename (without ".css" extension) * relative to wp-admin/. Defaults to 'wp-admin'. */ echo apply_filters( 'wp_admin_css', $stylesheet_link, $file ); if ( function_exists( 'is_rtl' ) && is_rtl() ) { $rtl_stylesheet_link = sprintf( "<link rel='stylesheet' href='%s' type='text/css' />n", esc_url( wp_admin_css_uri( "$file-rtl" ) ) ); /** This filter is documented in wp-includes/general-template.php */ echo apply_filters( 'wp_admin_css', $rtl_stylesheet_link, "$file-rtl" ); } }
function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
	// For backward compatibility.
	$handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;

	if ( wp_styles()->query( $handle ) ) {
		if ( $force_echo || did_action( 'wp_print_styles' ) ) {
			// We already printed the style queue. Print this one immediately.
			wp_print_styles( $handle );
		} else {
			// Add to style queue.
			wp_enqueue_style( $handle );
		}
		return;
	}

	$stylesheet_link = sprintf(
		"<link rel='stylesheet' href='%s' type='text/css' />n",
		esc_url( wp_admin_css_uri( $file ) )
	);

	/**
	 * Filters the stylesheet link to the specified CSS file.
	 *
	 * If the site is set to display right-to-left, the RTL stylesheet link
	 * will be used instead.
	 *
	 * @since 2.3.0
	 * @param string $stylesheet_link HTML link element for the stylesheet.
	 * @param string $file            Style handle name or filename (without ".css" extension)
	 *                                relative to wp-admin/. Defaults to 'wp-admin'.
	 */
	echo apply_filters( 'wp_admin_css', $stylesheet_link, $file );

	if ( function_exists( 'is_rtl' ) && is_rtl() ) {
		$rtl_stylesheet_link = sprintf(
			"<link rel='stylesheet' href='%s' type='text/css' />n",
			esc_url( wp_admin_css_uri( "$file-rtl" ) )
		);

		/** This filter is documented in wp-includes/general-template.php */
		echo apply_filters( 'wp_admin_css', $rtl_stylesheet_link, "$file-rtl" );
	}
}

常見問題

FAQs
檢視更多 >