markdown在wordpress中使用jquery代码片段(代码片段)

author author     2022-12-15     505

关键词:

I was trying to get the fitVids.js to work on a WP site, and couldn't get it! I'd copied and pasted their example code, switched out my own selectors, and nothing!!! I kept trying different selectors, messed around a bit with the code, no dice. Finally checked the terminal and saw that I had an error.

# [TypeError: $ is not a function when calling jQuery function](https://stackoverflow.com/questions/12343714/typeerror-is-not-a-function-when-calling-jquery-function)

I have a simple jQuery script in a WordPress plugin that is using a jQuery wrapper like this:
```
$(document).ready(function()

    // jQuery code is in here

);
```
I am calling this script from within the WordPress Dashboard and am loading it AFTER the jQuery framework has loaded.

When I check the page in Firebug I constantly keep receiving the error message:

```error
TypeError: $ is not a function

$(document).ready(function()
```

Should I maybe wrap the script in this function:

```
(function($)

    // jQuery code is in here

)(jQuery);
```
I have had this error quite a few times and am not sure how to handle it.

Any help would be greatly appreciated.
 -----
 
[Matthew Blancarte replies](https://stackoverflow.com/a/12343735/6412747):

This should fix it:

```
jQuery(document).ready(function($)
  //you can now use $ as your jQuery object.
  var body = $( 'body' );
);
```

Put simply, WordPress runs their own scripting before you can and they release the $ var so it won't collide with other libraries. This makes total sense, as WordPress is used for all kinds of web sites, apps, and of course, blogs.

From their documentation:

> The jQuery library included with WordPress is set to the noConflict() mode (see wp-includes/js/jquery/jquery.js). This is to prevent compatibility problems with other JavaScript libraries that WordPress can link.

> In the noConflict() mode, the global $ shortcut for jQuery is not available...

markdown在twig文件中使用wordpress功能(代码片段)

查看详情

markdown用于预处理字段的wordpress自定义php函数在twig模板中使用之前(代码片段)

查看详情

markdown在wordpress中获取当前页面(代码片段)

查看详情

markdown在wordpress中创建和使用自定义全局变量。(代码片段)

查看详情

如何在 wordpress 帖子中使用降价

】如何在wordpress帖子中使用降价【英文标题】:Howtousemarkdownforwordpressposts【发布时间】:2017-11-1605:00:27【问题描述】:我已经安装并设置了XAMPP(v.5.6.30-1)和Wordpress(v.4.8)用于一些测试,我想在Markdown中写帖子。我发现了这个officialsu... 查看详情

wordpress的神器

...言,旨在帮助你花费更小的代价来格式化纯文本文档。在WordPress下你可以使用HTML或者可视化编辑器来格式化你的文档,但是使用markdown可以让格式化文档变得更加容易,而且你随时可以导出成很多种格式,包括(但不限于)HTML... 查看详情

wordpress安装markdown插件

WordPress安装插件实现使用Markdown风格的博客一、前言前文实现了树莓派/Debian构建LAMPWeb服务器并搭建WordPress博客,本文就如何在WordPress里实现使用Markdown风格的博客。Markdown简述Markdown的目标是实现「易读易写」。可读性,无论如... 查看详情

在wordpress中用html替换markdown

】在wordpress中用html替换markdown【英文标题】:Replacemarkdownwithhtmlinwordpress【发布时间】:2021-03-2114:44:57【问题描述】:我正在尝试替换自定义帖子中的所有wiki降价文本。示例:==MySubheading=====MysubSubheading=======anotherheading====我正在... 查看详情

markdown如何在带有timber/twig的wordpress网站上启用和使用yoastbreadcrumbs(代码片段)

查看详情

markdown如何在带有timber/twig的wordpress网站上启用和使用yoastbreadcrumbs(代码片段)

查看详情

markdown使用wp-cli在服务器上存储wordpress文件和数据库。(代码片段)

查看详情

markdown使wordpress帖子中的视频嵌入响应。(代码片段)

查看详情

markdown使用命令行使用新的图像大小重新生成wordpress图像(代码片段)

查看详情

markdown使用命令行使用新的图像大小重新生成wordpress图像(代码片段)

查看详情

markdown使用git和subversion镜像进行wordpress插件开发(代码片段)

查看详情

markdown使用git和subversion镜像进行wordpress插件开发(代码片段)

查看详情

markdown使用wp-cli导出wordpress数据库(代码片段)

查看详情

markdown从wordpress中删除上下文帮助和屏幕选项(代码片段)

查看详情