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' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路