doutangkao2789 2014-07-17 08:35
浏览 56
已采纳

Functions.php wordpress不适用于样式表或jquery

I am making my first custom wordpress theme and am running into problems with functions.php

I am using bootstrap too so i want to include bootstrap stylesheets to wp i currently do it this way-:

style.css

@import url('css/bootstrap.css');
@import url('css/font-awesome.css');

I understand that i can use functions.php to do the same, so i wrote a custom function and tried to do it like this-:

functions.php

<?php
/* Theme setup */
require_once('wp_bootstrap_navwalker.php');

/* Add bootstrap support to the Wordpress theme*/

function theme_add_bootstrap() {
    wp_enqueue_style( 'bootstrap-css', get_template_directory_uri().'/css/bootstrap.css' );
    wp_enqueue_style( 'style-css', get_template_directory_uri().'/css/font-awesome.css' );
    wp_enqueue_script( 'bootstrap-js', get_template_directory_uri().'/js/bootstrap.js', array(), '3.0.0', true );
}

add_action( 'wp_enqueue_scripts', 'theme_add_bootstrap' );

?>

This does not seem to work. Neither does functions.php load the wp jquery or the bootstrap.js

Can anyone shed some light onto this matter for me? I would be ever grateful. This is not a child theme its a custom theme.

  • 写回答

1条回答 默认 最新

  • duanliangman5398 2014-07-17 08:59
    关注

    Try registering your scripts before you enqueue them. For example:

    function my_enqueue_scripts() {
        // Register Bootstrap JS.
        wp_register_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ), NULL, true );
        // Enqueue Bootstrap JS.
        wp_enqueue_script( 'bootstrap-js' );
    }
    
    add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)