【发布时间】:2020-03-14 00:23:37
【问题描述】:
这是我的第一篇文章!
我对编码有点陌生,我知道足够多的 html 和 css,并使用诸如 bootstrap 之类的框架来开发一个基本的网站,并且已经开始学习如何使用 php 在 wordpress 中构建主题。
我的目标是使用 bootstrap 和 javascript 构建一个主题,但我在执行最简单的任务时遇到了麻烦,例如让脚本在 functions.php 中运行。我一直在关注一些在线教程,但这些教程不起作用,经过大量的实验和研究,我似乎无法得到任何工作。
我的functions.php代码是:
<?php
function styles() {
wp_register_style('bootstrap', get_template_directory_uri() . '/bootstrap/css/bootstrap.min.css' );
$dependencies = array('bootstrap');
wp_enqueue_style( 'bootstrapstarter-style', get_stylesheet_uri(), $dependencies );
wp_register_style('style', get_template_directory_uri() . 'style.css');
$dependencies = array('style');
wp_enqueue_style('style', get_stylesheet_uri(), $dependencies);
}
add_action( 'wp_enqueue_scripts', 'styles' );
function scripts() {
wp_deregister_script('jquery3.4.1');
wp_enqueue_script('jquery3.4.1', get_template_directory_uri() . 'jquery-3.4.1.min.js', '', 1, true);
$dependencies = array('jquery');
wp_enqueue_script('bootstrap', get_template_directory_uri() .'/bootstrap/js/bootstrap.min.js', $dependencies, '3.3.6', true );
wp_enqueue_script('customjs', get_template_directory_uri() . 'scripts.js', '', 1, true);
}
add_action( 'wp_enqueue_scripts', 'scripts' );
function title(){
add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'title' );
?>
我有一段测试代码,它在 scripts.js 中显示一个弹出警报(页脚正在调用 ?php wp_footer();?):
$(document).ready(function(){
alert('test');
})
我还尝试过加载顺序,认为引导 js 可能会干扰我自己的 js,但无论我如何定位它们,我都无法让它们工作。
抱歉,如果这是一个愚蠢的问题,并且以前曾有人问过这个问题,但我没有查到似乎没有任何帮助,我们将不胜感激。
非常感谢!
【问题讨论】:
标签: javascript php jquery wordpress function