Я новичок в WordPress. Я включаю мой файл, используя
<link rel='stylesheet' href="<?php bloginfo("stylesheet_url")?>"/>
Но если я закрою свой файл css в functions.php
он не работает. Зачем? Где моя ошибка?
<?php wp_enqueue_style('style',get_template_directory_uri())?>
Какое решение для этого?
Вы неправильно вызываете функцию. Вы не указали свое имя, просто каталог.
Из кода
wp_enqueue_style( string $handle, string $src = false, array $deps = array(), string|bool|null $ver = false, string $media = 'all' )
поэтому в вашем случае вы должны ставить в очередь так
add_action( 'wp_enqueue_scripts', 'wpse_my_style' ); function wpse_my_style(){ wp_enqueue_style( 'my-style', get_stylesheet_directory_uri() . 'path/to/your/css' ); }
остальные параметры являются необязательными
function wpdocs_style() { wp_enqueue_style( 'style-name', get_stylesheet_uri() ); //This is for getting style.css of current theme wp_enqueue_style( 'style-name1', get_teplate_directory_uri() . '/css/custom.css', array('jquery') ); //This is for getting other css file from parent directory wp_enqueue_script( 'script-name1', get_teplate_directory_uri() . '/js/custom.js', array('jquery') ); //This is for getting JS file from parent directory } add_action( 'wp_enqueue_scripts', 'wpdocs_style' ); OR //Or as an laternate you can hook with wp_head also add_action( 'wp_head', 'wpdocs_style' );
Для запуска указанной функции необходимо добавить <?php wp_enqueue_script("jquery"); ?>
<?php wp_enqueue_script("jquery"); ?>
(Если вы используете это действие add_action( 'wp_enqueue_scripts', 'wpdocs_style' );
) в header.php
</head>
.
Вы должны назначить имя для каждого стиля (например, присваивать имя стиля, style-name1 и т. Д.), А имя должно быть уникальным. И если вы хотите qnqueue из функции child.php дочерней темы, тогда вы должны использовать get_stylesheet_directory_uri()
вместо get_teplate_directory_uri()
.