如何向 WordPress 添加一个简单的 jQuery 脚本? [英] How do I add a simple jQuery script to WordPress?

查看:35
本文介绍了如何向 WordPress 添加一个简单的 jQuery 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了 Codex 和一些关于在 WordPress 中使用 jQuery 的博客文章,这非常令人沮丧.我已经在 functions.php 文件中加载了 jQuery,但是所有的指南都很糟糕,因为它们假设您已经拥有大量的 WordPress 经验.例如,他们说现在我正在通过 functions.php 文件加载 jQuery,现在我要做的就是加载我的 jQuery.

I read the Codex and a few blog posts about using jQuery in WordPress, and its very frustrating. I've got as far as loading jQuery in functions.php file, but all of the guides out there are crappy because they assume you already have a ton of WordPress experience. For instance, they say that now that I'm loading jQuery through the functions.php file, now all I have to do is load my jQuery.

我究竟该怎么做?具体来说,我应该向哪些文件添加代码?我究竟如何为单个 WordPress 页面添加它?

How exactly do I do this? What files, specifically, do I add code to? How exactly do I add it for a single WordPress page?

推荐答案

我知道您对教程的意思.这是我的做法:

I know what you mean about the tutorials. Here's how I do it:

首先,您需要编写脚本.在您的主题文件夹中创建一个名为js"的文件夹.在该文件夹中为您的 javascript 创建一个文件.例如.你的脚本.js.将您的 jQuery 脚本添加到该文件(您不需要在 .js 文件中使用

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆