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

WordPress中出现Uncaught TypeError: $(...).dataTable不是函数错误求助

Fixing "Uncaught TypeError: $(...).dataTable is not a function" with TablePress in WordPress

Hey there, let's fix that frustrating Uncaught TypeError: $(...).dataTable is not a function error you're seeing with TablePress on your WordPress site. I’ve debugged this exact issue dozens of times, so let’s walk through the most common fixes step by step:

  • Verify TablePress DataTables settings
    Head to your WordPress dashboard, go to TablePress → Plugin Options. Make sure:

    • The "Load DataTables library" option is set to either "On demand" or "Always" (not "Never").
    • For the specific table on your page, confirm its shortcode includes the datatables="true" attribute, like this: [table id=YOUR_TABLE_ID datatables="true"/]
      Double-check that the table's individual settings (under TablePress → Your Table → Features of the table) have "Use DataTables" enabled.
  • Resolve jQuery conflicts
    WordPress uses jQuery in noConflict mode by default, which means the $ shortcut might not work if another plugin or theme overrides it. Here's how to fix this:

    • If you have custom JavaScript on the site, replace any $(document).ready(function() { ... }) blocks with jQuery(document).ready(function($) { ... }) — this lets you use $ safely inside the function.
    • Check if your theme or another plugin is loading a duplicate version of jQuery. Many themes load their own jQuery copy, which conflicts with WordPress's native version. Disable the theme's custom jQuery load (look for code like wp_enqueue_script('jquery', 'EXTERNAL_URL') in your theme's functions.php) and use WordPress's built-in jQuery instead.
  • Check script loading order
    DataTables must load after jQuery — if it loads first, you'll get this error. Use your browser's DevTools (F12 → Network → JS tab) to confirm:

    • jquery.min.js loads before jquery.dataTables.min.js and any TablePress-related DataTables scripts.
      If the order is wrong, you can adjust script dependencies using WordPress's wp_enqueue_script function. For example, ensure DataTables scripts declare jquery as a dependency:
    wp_enqueue_script( 'tablepress-datatables', 'PATH_TO_SCRIPT', array( 'jquery' ), 'VERSION', true );
    
  • Clear all caches
    Caching plugins (WP Rocket, W3 Total Cache, etc.) often merge or delay scripts, breaking DataTables loading. Do the following:

    • Clear your site's server-side cache via your caching plugin's settings.
    • Force-refresh your browser (Ctrl+Shift+R on Windows/Linux, Cmd+Shift+R on Mac) to clear local cache.
  • Debug plugin conflicts
    Another plugin might be interfering with TablePress's scripts. Test this by:

    • Disabling all plugins except TablePress, then refresh the page. If the error goes away, you know a plugin is causing the conflict.
    • Re-enable plugins one by one, checking the page after each, to find the culprit. Once found, update the plugin, contact its developer for a fix, or swap it with an alternative.
  • Test theme compatibility
    Some themes modify jQuery behavior or load scripts incorrectly. Switch temporarily to a default WordPress theme (like Twenty Twenty-Four) and check if the error disappears. If it does:

    • Look for jQuery-related code in your theme's functions.php or header.php that might be causing issues.
    • Reach out to the theme developer for compatibility guidance with TablePress.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 03:43:09