繁体   English   中英

如何在wordpress主题中从cdn添加外部js文件和jq库?

[英]How to add external js file and jq library from cdn in wordpress theme?

在这里输入图像描述我在我的WordPress主题中调用我的外部Js文件,但它显示一些错误而无法正常工作

我做了可能的方式,但它没有工作。

function creative_resources() {
    wp_enqueue_style('style', get_stylesheet_uri(), '', 1.0);
    wp_enqueue_script('script', get_template_directory_uri().'/js/main.js', array('jquery'), 1.1, true);
    wp_enqueue_script('script-jqlib', get_template_directory_uri().'js/jquery-1.9.0.min.js', array('jquery'), 1.1, true);
}

add_action('wp_enqueue_scripts', 'creative_resources');

我只想要从我的main.js文件中调用的wp主题中的粘性菜单。 调用Main.js文件,但显示一些错误,并且jq库无法加载....

Uncaught TypeError: $ is not a function
    at main.js?ver=1.1:2

 Failed to load resource: the server responded with a status of 404 (Not Found)jquery-1.9.0.min.js:1

您应该将main.js文件修改为:

jQuery(document).ready(function($) {

    // Your Code that uses jQuery's $ can follow here.
});

请参阅jQuery.noConflict()

https://crunchify.com/how-to-fix-wordpress-uncaught-typeerror-is-not-a-function-jquery-error/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM