You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress网站jQuery加载异常求助:寻求排查方向

Hey there! Since you're more familiar with Drupal and Laravel, let's break down how to troubleshoot these jQuery issues in WordPress step by step—no need to feel lost here.

1. First, confirm jQuery is loading properly (especially on that specific page)

  • Fire up your browser's dev tools (F12), head to the Network tab, refresh the /property/?code=23 page, and search for jquery. Check if it loads with a 200 status code—if it's failing to load, that's the root cause right there.
  • Also, remember: WordPress loads jQuery in no-conflict mode by default, which means the $ shortcut isn't available unless you explicitly enable it. If your custom scripts use $, you have two fixes:
    • Replace all instances of $ with jQuery, or
    • Wrap your code in a self-executing function to map $ to jQuery:
      (function($) {
        // Your code that uses $ goes here
      })(jQuery);
      
    This is the most common reason for the Uncaught TypeError: $ is not a function error.

2. Verify script loading order

  • Plugins like unslider or that directory component depend entirely on jQuery—they must load after jQuery finishes loading. In WordPress, the right way to do this is using wp_enqueue_script and declaring jquery as a dependency. For example:
    wp_enqueue_script(
      'unslider-script',
      get_template_directory_uri() . '/js/unslider.min.js',
      array('jquery'), // This tells WordPress to load jQuery first
      '1.0.0',
      true // Loads the script in the footer, which is best practice
    );
    
  • Check if the /property/?code=23 page has any custom script loading logic (like conditional scripts for query parameters) that's breaking this order. Maybe the dependent scripts are loading before jQuery here.

3. Check for version conflicts or duplicate jQuery loads

  • Some themes or plugins might load their own version of jQuery, which can clash with WordPress's native copy. To check the loaded version, open the dev tools console and run:
    jQuery.fn.jquery
    
  • Compare this to your WordPress core's default jQuery version (you can find this in /wp-includes/js/jquery/). If there's a mismatch or multiple jQuery files loading, track down which theme/plugin is causing it. You can deregister the conflicting version with wp_deregister_script('jquery') and re-register the core version, but be careful—many plugins rely on WordPress's native jQuery.

4. Dig into the specific page's logic

  • Since the error only happens when ?code=23 is present, look at the template for this page (maybe page-property.php, a custom post type template, or a template part loaded conditionally). Ask:
    • Are the directory or unslider scripts only loaded when this query parameter exists? If so, is their loading logic broken?
    • Is there any custom JavaScript that runs only when code=23 is set, and that script is either missing jQuery or using $ incorrectly?

5. Test for theme/plugin conflicts

  • A quick way to narrow things down:
    1. Switch temporarily to a default WordPress theme (like Twenty Twenty-Four) and refresh the page. If the errors disappear, the issue is in your current theme's script loading code.
    2. If the theme isn't the problem, disable plugins one by one, refreshing the page after each disable. When the errors vanish, you've found the conflicting plugin—check its script enqueuing logic for issues.

6. Fix the first error first

  • Notice that the $ is not a function error comes first. JavaScript stops executing subsequent code when it hits an uncaught error, so the directory and unslider errors might just be side effects of jQuery not being properly accessible. Fix the $ issue first, then see if the other errors go away.

内容的提问来源于stack exchange,提问作者BigD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 10:08:57