使用functions.php将Bootstrap添加到Wordpress [英] Adding Bootstrap to Wordpress Using functions.php

查看:25
本文介绍了使用functions.php将Bootstrap添加到Wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下代码将 Bootstrap 嵌入到 Wordpress,但它不起作用.需要帮助.......

I have tried using the following code to embed Bootstrap to Wordpress but it doesn't work. Need help..........

<?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 将在 functions.php 中使用 wp_enqueue_style 和 wp_enqueue_script.特别是,我们需要创建一个新函数来添加(或入队)css 样式和 js 脚本,然后通过添加 wp_enqueue_scripts 操作让 WordPress 在适当的时候调用它.

WordPress is to use wp_enqueue_style and wp_enqueue_script from within functions.php. In particular, we need to create a new function that adds (or enqueues) the css style and the js script and then allow WordPress to call it at the right moment by adding a wp_enqueue_scripts action.

/* 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' );

参考:点击这里

这篇关于使用functions.php将Bootstrap添加到Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆