我在实时服务器上的 WordPress 项目没有排队 JS 文件(收到 404 错误)

My WordPress project on the live server is not enqueuing JS files (404 Error Recieved)

我正在开发自定义 Wordpress 主题,但是一旦我将项目加载到实时服务器,它就会停止对我的 JS 文件进行排队 - 并向我提供 404 错误。

此外,我所有加载的字体文件和 CSS 样式表都遇到了同样的问题

这些文件在我的本地主机上正确加载,只有在我将它们加载到实时服务器上时才会中断。

我调查了 wp_enqueue_script() 和
wp_enqueue_style(),但是我仍然遇到这个问题。

我的 functions.php 文件包含以下脚本:

function custom_theme_scripts() {
    wp_enqueue_style( 'custom-theme-style', get_stylesheet_uri(), array(), '20190512', 'all' );

    wp_enqueue_script( 'jqueryScripts', get_template_directory_uri() . '/js/jqueryScripts.js', array ( 'jquery' ), 1.1, true);
}

add_action( 'wp_enqueue_scripts', 'sierra_ridge_scripts' );

上述脚本的结果是 404 Error 出现在调试器控制台中。

首先你可以在 add_action 中调用错误的函数,如果你检查你的代码你明白了。

function custom_theme_scripts() {
    wp_enqueue_style( 'custom-theme-style', get_stylesheet_uri(), array(), '20190512', 'all' );

    wp_enqueue_script( 'jqueryScripts', get_stylesheet_directory_uri() . '/js/jqueryScripts.js', array ( 'jquery' ), 1.1, true);
}

add_action( 'wp_enqueue_scripts', 'custom_theme_scripts' );

请尝试使用此代码并再次检查。