wp_admin_css

Enqueues or directly prints a stylesheet link to the specified CSS file.

Description

wp_admin_css( (string) $file = 'wp-admin', (bool) $force_echo = false ); 

"Intelligently" decides to enqueue or to print the CSS file. If the action has *not* yet been called, the CSS file will be enqueued. If the action has been called, the CSS link will be printed. Printing may be forced by passing true as the $force_echo (second) parameter.

For backward compatibility with WordPress 2.3 calling method: If the $file (first) parameter does not correspond to a registered CSS file, we assume $file is a file relative to wp-admin/ without its .css extension. A stylesheet link to that generated URL is printed.

Parameters (2)

0. $file — Optional. (string) => 'wp-admin'
Style handle name or file name (without .css extension) relative to wp-admin/. Defaults to wp-admin..
1. $force_echo — Optional. (bool) => false
Force the stylesheet link to be printed rather than enqueued.

Usage

  1. if ( !function_exists( 'wp_admin_css' ) ) { 
  2. require_once ABSPATH . WPINC . '/general-template.php'; 
  3.  
  4. // Optional. Style handle name or file name (without ".css" extension) relative 
  5. // to wp-admin/. Defaults to 'wp-admin'. 
  6. $file = 'wp-admin'; 
  7.  
  8. // Optional. Force the stylesheet link to be printed rather than enqueued. 
  9. $force_echo = false; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = wp_admin_css($file, $force_echo); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/general-template.php  
  1. function wp_admin_css( $file = 'wp-admin', $force_echo = false ) { 
  2. // For backward compatibility 
  3. $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file; 
  4.  
  5. if (wp_styles)->query( $handle ) ) { 
  6. if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately 
  7. wp_print_styles( $handle ); 
  8. else // Add to style queue 
  9. wp_enqueue_style( $handle ); 
  10. return; 
  11.  
  12. /** 
  13. * Filters the stylesheet link to the specified CSS file. 
  14. * If the site is set to display right-to-left, the RTL stylesheet link 
  15. * will be used instead. 
  16. * @since 2.3.0 
  17. * @param string $file Style handle name or filename (without ".css" extension) 
  18. * relative to wp-admin/. Defaults to 'wp-admin'. 
  19. */ 
  20. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file ); 
  21.  
  22. if ( function_exists( 'is_rtl' ) && is_rtl() ) { 
  23. /** This filter is documented in wp-includes/general-template.php */ 
  24. echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );