首页 > 解决方案 > jQuery 没有在 Wordpress 上定义-smoothstate Js

问题描述

我正在尝试将 smoothState.js 安装到我的 wordpress 主题中。它不工作,在调试时,我看到了这个错误——“jQuery 没有定义”。这是在我复制过来的 smoothState.js 文件中。

谁能帮我这个?我是否错误地安装了文件?我尝试在函数之后添加(jQuery)注释,但它仍然无法正常工作。感谢帮助!错误是针对下面的这个特定功能

/*!
 * smoothState.js is jQuery plugin that progressively enhances
 * page loads to behave more like a single-page application.
 *
 * @author  Miguel Ángel Pérez   reachme@miguel-perez.com
 * @see     http://smoothstate.com
 *
 */

(function (factory) {
  'use strict';

  if(typeof module === 'object' && typeof module.exports === 'object') {
    factory(require('jquery'), window, document);
  } else {
    factory(jQuery, window, document);
  }

标签: phpjquerywordpresssmoothstate.js

解决方案


看起来 smoothState.js 是在 jQuery 准备好之前加载的。

您如何将 smoothState 添加到您的页面?使用 wp_enqueue_script?

另外,smoothState 是如何在 JS 中加载的?

此链接可能会对您有所帮助https://webdesign.tutsplus.com/tutorials/how-to-integrate-smoothstatejs-into-a-wordpress-theme--cms-26610


推荐阅读