Szukaj…


Składnia

  1. wp_enqueue_style ($ uchwyt, $ src, $ zależność, $ wersja, $ media);

Parametry

Parametr Detale
$handle (Ciąg) (wymagane) Unikalna nazwa arkusza stylów.
$src (Ciąg) (Opcjonalnie) URL arkusza stylów, który będzie używany w atrybucie src znacznika linku .
$deps (String) (Opcjonalnie) Tablica stylów obsługi zależy od tego arkusza stylów.
$ver (Ciąg) (Opcjonalnie) Ciąg określający wersję arkusza stylów.
$media (String) (Opcjonalnie) Nośnik, dla którego utworzono ten arkusz stylów. np. „wszystko”, „drukuj”, „ekran” itp

Dołączanie wewnętrznego pliku css z innym plikiem css jako zależnością

function themeSlug_enqueue_scripts() {
    wp_enqueue_style( 'themeSlug-reset', get_template_directory_uri() .'/css/reset.css', '1.0.0' );
    wp_enqueue_style( 'themeSlug-style', get_template_directory_uri() .'/style.css', 'themeSlug-reset', '1.0.0');
}
add_action('wp_enqueue_scripts', 'themeSlug_enqueue_scripts');

W tym wewnętrzny plik css

W tym przypadku style.css znajduje się w katalogu głównym folderu motywu

function themeSlug_enqueue_scripts() {
    wp_enqueue_style( 'themeSlug-style', get_template_directory_uri() .'/style.css', '1.0.0');
}
add_action('wp_enqueue_scripts', 'themeSlug_enqueue_scripts');

W tym zewnętrzny plik css

W tym przykładzie chcemy dołączyć czcionkę niesamowite ikony czcionki

function themeSlug_enqueue_scripts() {
    wp_enqueue_style( 'font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css');
}
add_action('wp_enqueue_scripts', 'themeSlug_enqueue_scripts');

Kolejkuj arkusze stylów tylko dla IE

add_action( 'wp_enqueue_scripts', 'enqueue_my_styles_and_scripts' );

/**
 * Enqueue styles (or scripts) conditionally.
 *
 * Load stylesheets (or scripts) specifically for IE. IE10 and above does
 * not support conditional comments in standards mode.
 *
 * @link https://gist.github.com/wpscholar/4947518
 * @link https://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
 */
function enqueue_my_styles_and_scripts() {

    // Internet Explorer specific stylesheet.
    wp_enqueue_style( 'themename-ie', get_stylesheet_directory_uri() . '/css/ie.css', array( 'twentyfifteen-style' ), '20141010' );
    wp_style_add_data( 'themename-ie', 'conditional', 'lte IE 9' );

    // Internet Explorer 7 specific stylesheet.
    wp_enqueue_style( 'themename-ie7', get_stylesheet_directory_uri() . '/css/ie7.css', array( 'twentyfifteen-style' ), '20141010' );
    wp_style_add_data( 'themename-ie7', 'conditional', 'lt IE 8' );

}

W tym wewnętrzny plik css dla twojej klasy wtyczek


class My_Plugin() {
  function __construct() {
    add_action( 'wp_enqueue_scripts', array( $this, 'init_fe_assets' ) );
  }

  public function init_fe_assests() {
    wp_enqueue_style( 'my-plugin', plugin_dir_url( __FILE__ ) . 'assets/css/frontend/plugin.css', array(), '0.0.1', true );
  }
}

new My_Plugin();

Dodaj alternatywne arkusze stylów

    <?php wp_enqueue_style('theme-five', get_template_directory_uri() . '/path/to/additional/css'); 
wp_style_add_data('theme-five', 'alt', true); 
wp_style_add_data('theme-five', 'title', __('theme-five.css', 'your-theme-name')); ?>

wp_style_add_data



Modified text is an extract of the original Stack Overflow Documentation
Licencjonowany na podstawie CC BY-SA 3.0
Nie związany z Stack Overflow