子主题 - Javascript 未触发

Child theme - Javascript not firing

本文关键字:Javascript      更新时间:2023-09-26

我正在尝试为我的插件加载 javascript 文件,它一直有效,直到我将主题更改为子主题,然后更新原始主题......知道为什么 JavaScript 停止发射吗?我包含在子主题文件夹中的只是一个样式.css文件。

没有触发的javascript行显然是:

wp_enqueue_script('watchlist',THT_WATCHLIST_DIR.'assets/js/watchlist.js',array('jquery','jquery-ui-1','jquery-ui-tabs1','jquery-ui-datepicker1','jquery-ui-dialog1','jquery-ui-button1',), '1.0.0', 1 );

谢谢!

----main plugin file-----
function tht_add_javascript_files() {
if (!is_admin()) {
    wp_enqueue_style('watchlist-css',THT_WATCHLIST_DIR.'assets/css/watchlist.css' );
    wp_enqueue_script( 'jquery-ui-datepicker1', '/wp-includes/js/jquery/ui/jquery.ui.datepicker.min.js', array('jquery-ui-core'), '1.10.3', 1 );
    wp_enqueue_script( 'jquery-ui-position', '/wp-includes/js/jquery/ui/jquery.ui.position.min.js', array('jquery'), '1.10.3', 1 );
    wp_enqueue_script( 'jquery-ui-dialog1', '/wp-includes/js/jquery/ui/jquery.ui.dialog.min.js', array('jquery','jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position','jquery-ui-button1'), '1.10.3', 1 );
    wp_enqueue_script( 'jquery-ui-button1', '/wp-includes/js/jquery/ui/jquery.ui.button.min.js', array('jquery','jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position'), '1.10.3', 1 );
    wp_enqueue_script( 'jquery-ui-tabs1', '/wp-includes/js/jquery/ui/jquery.ui.tabs.min.js', array('jquery-ui-widget'), '1.10.3', 1 );
    wp_enqueue_script( 'jquery-ui-menu', '/wp-includes/js/jquery/ui/jquery.ui.menu.min.js', array( 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position' ), '1.10.3', 1 );
    wp_enqueue_script( 'jquery-ui-1', '/wp-includes/js/jquery/ui/jquery.ui.autocomplete.min.js', array('jquery-ui-core', 'jquery-ui-widget'), '1.10.3', 1 );
    wp_enqueue_script('watchlist',THT_WATCHLIST_DIR.'assets/js/watchlist.js',array('jquery','jquery-ui-1','jquery-ui-tabs1','jquery-ui-datepicker1','jquery-ui-dialog1','jquery-ui-button1',), '1.0.0', 1 );
}
}
add_action('wp_enqueue_scripts', 'tht_add_javascript_files');

id说父主题中的某个地方是

define(THT_WATCHLIST_DIR, get_stylesheet_directory() );

它需要:

define(THT_WATCHLIST_DIR, get_template_directory() );

因此,您可以使用子主题。要么更改主题并让开发人员知道这一点,要么将您的 js 文件夹复制到子主题中!

更新

我收到所有js文件和页面的404错误。可能有一些原因导致了这种情况。首先处理您的 404 问题

  1. 刷新您的永久链接,复制您的 .htaccess 文件并保存在某个地方将 .htaccess 文件的内容替换为以下内容:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    ErrorDocument 404 /index.php?error=404
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    
  2. 撤消您所做的主题更改。

  3. 检查您的WP选项数据库表 - home_url/site_url的值是多少?
  4. 您的服务器上启用了 Apache mod_rewrite?

对于您的文件 1.检查主题中实际存在的文件夹JS" 2. 检查 JS 文件的文件夹权限 ->主题中的目录应为 755。 3.尝试2014主题->检查浏览器控制台(右键单击页面元素->检查元素,然后单击弹出窗口中的控制台)是否有任何错误?如果没有再次检查您的主题网址到js文件夹,如果出现错误,请联系您的主机或再次检查您的apache设置。