Php Jquery在wordpress中不起作用

Php Jquery在wordpress中不起作用,php,jquery,wordpress,Php,Jquery,Wordpress,这可能是一个简单的问题,但无论我遵循什么教程,我的Jquery在我的主题上都无法工作 我的js文件位于/js/jquery.js,其中的代码仅用于测试目的: jQuery(document).ready(function($) { $('#banner').hide(); }); my functions.php文件与索引位于同一位置,我为此编写的代码是: <?php function add_my_script() { wp_enqueue_script(

这可能是一个简单的问题,但无论我遵循什么教程,我的Jquery在我的主题上都无法工作

我的js文件位于/js/jquery.js,其中的代码仅用于测试目的:

jQuery(document).ready(function($) {


$('#banner').hide();
});
my functions.php文件与索引位于同一位置,我为此编写的代码是:

    <?php
function add_my_script() {
    wp_enqueue_script(
        'jquery', // name your script so that you can attach other scripts and de-register, etc.
        get_template_directory_uri() . 'js/jquery.js', // this is the location of your script file
        array('jquery') // this array lists the scripts upon which your script depends
    );
}
add_action( 'wp_enqueue_scripts', 'add_my_script' );
?>

什么也没发生。。。有人能纠正我做错了什么吗?这就是我不喜欢使用wordpress的原因。

很可能你需要在js之前用斜杠:

获取\u模板\u目录\u uri'/js/jquery.js'

也就是说,您可以使用浏览器开发工具中的网络监视器检查您的站点。它将显示正在获取的URL。或者只是检查一下开发工具的控制台。如果无法获取jQuery文件,它可能会显示404错误

wp_enqueue_script(
    'call this something else!', // name your script so that you can attach other scripts and de-register, etc.
    get_template_directory_uri() . '/js/jquery.js', // this is the location of your script file
    array('jquery') // this array lists the scripts upon which your script depends
);
您有几个输入错误……还可以使用chrome或Firefox中的dev.console检查jquery是否可用。右键单击页面,单击inspect元素,然后单击console,您将得到一个错误jquery undefined或类似错误

此外,在前端的页面上:

get_header();
get_footer();

您不使用head标记,因为这些函数会拉入头文件和脚文件。如果没有get\u header&get\u footer,您将遇到问题:

这是一个主题、插件还是什么?不只是自定义jquery,您可能根本不需要包含jquery。wordpress为你做的,嗯。。。由于您正在尝试编写代码,请打开浏览器控制台,查看是否有错误。还可以查看该控制台中的network选项卡,以查看jquery实际上已经加载。横幅本来是要隐藏的,但是它什么也没做?我加了鞭子,但它什么也没做。我很确定这是你的问题,但没问题。你能检查一下开发工具吗?我对wordpress很陌生。。。什么是开发人员工具?它在哪里?XD您可以使用Chrome并检查我已经在开发者工具上使用了源代码位,并且它似乎没有加载文件