Добавление бутстрапа в WordPress с помощью functions.php

Я попытался использовать следующий код для вставки Bootstrap в WordPress, но он не работает. Нужна помощь……….

<?php function resources() { wp_enqueue_style('style',get_stylesheet_uri()); wp_enqueue_style('bootstrap.min',get_template_directory_uri().'/css/bootstrap.min.css'); wp_enqueue_style('bootstrap',get_template_directory_uri().'/css/bootstrap.css'); wp_enqueue_style('bootstrap-theme.min',get_template_directory_uri().'/css/bootstrap-theme.min.css'); } add_action('wp_enqueue_scripts', 'resources'); 

Это может быть полезно для вас

WordPress должен использовать wp_enqueue_style и wp_enqueue_script из функций functions.php. В частности, нам нужно создать новую функцию, которая добавляет (или enqueues) стиль css и js-скрипт, а затем позволяет WordPress вызывать его в нужный момент, добавляя действие wp_enqueue_scripts.

 /* Add bootstrap support to the WordPress theme*/ function theme_add_bootstrap() { wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css' ); wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css' ); wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array(), '3.0.0', true ); } add_action( 'wp_enqueue_scripts', 'theme_add_bootstrap' ); 

Для справки: нажмите здесь

Для wp_enqueue_scripts работы wp_enqueue_scripts в function.php , <?php wp_head(); ?> <?php wp_head(); ?> необходимо разместить перед закрытием </head> и <?php wp_footer(); ?> <?php wp_footer(); ?> перед закрытием </body> в файле шаблона.

Поскольку вы не опубликовали свой файл шаблона, я думаю, что это может послужить причиной вашей проблемы.

Надеюсь, что эта помощь

Просто используйте загрузочный CDN – https://www.bootstrapcdn.com/

В своей дочерней теме найдите функцию theme_enqueue_styles () и добавьте две строки дополнительного кода, показанные ниже.

 function theme_enqueue_styles() { // Add the following two lines // wp_enqueue_style( 'bootstrap-cdn-css', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' ); wp_enqueue_script( 'bootstrap-cdn-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js' ); // ------ -------// wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style') ); }