简体   繁体   English

使用自定义wordpress主题配置particles.js

[英]Configuring particles.js with custom wordpress theme

I am currently working on a portfolio site and am trying to integrate a really handy feature called particles.js . 我目前正在投资组合网站上,并且正在尝试集成一个非常方便的功能,称为particles.js It works fine and is extremely easy to integrate in a static HTML page but the issue is I am developing a custom Wordpress theme and keep getting errors. 它工作正常,并且非常容易集成到静态HTML页面中,但是问题是我正在开发自定义Wordpress主题并不断出错。 I am using the designated CDN to bring in the script for particles.js and I have the json and app file saved locally in my files. 我正在使用指定的CDN来引入Particle.js的脚本,并且将json和app文件保存在本地文件中。 I am using enqueue for both of the js files that are necessary for this library to work. 我正在使用该库工作所需的两个js文件的入队。 I will link to code for the two local files and I will also link the CDN as well! 我将链接到两个本地文件的代码,并且还将链接CDN!

The link to the two files is here: https://gist.github.com/anonymous/5c6dc4675e93afb53ef97192628f2fe1 这两个文件的链接在这里: https : //gist.github.com/anonymous/5c6dc4675e93afb53ef97192628f2fe1

The link for the CDN is here: https://www.jsdelivr.com/package/npm/particles.js CDN的链接在这里: https : //www.jsdelivr.com/package/npm/particles.js

and the enqueue code goes as follows: 入队代码如下:

function wpb_adding_scripts() {
wp_enqueue_script('jquery');
wp_register_script('particles', 
'https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js');
wp_enqueue_script('particles');
wp_register_script('app', get_template_directory_uri() . '/js/app.js');
wp_enqueue_script('app');
}

add_action ('wp_enqueue_scripts', 'wpb_adding_scripts');

This is the errors that I am getting: 这是我得到的错误:

screenshot of errors 错误的屏幕截图

I have tried multiple things and nothing seems to work. 我已经尝试了多种方法,但似乎没有任何效果。 I attempted running it in different browsers but still it just doesn't want to work. 我尝试在不同的浏览器中运行它,但仍然不想运行。 As I stated before it works fine on a static HTML page but does not work with wordpress... I really need help with this because I have not found any information on integrating this library with a Wordpress site so any input is highly appreciated. 正如我之前所说的那样,它在静态HTML页面上可以正常运行,但不能与wordpress一起使用...我真的需要帮助,因为我没有找到有关将该库与Wordpress网站集成的任何信息,因此,我们非常感谢任何输入。 Thanks! 谢谢!

Please try this 请尝试这个

function wpb_adding_scripts() {
  wp_enqueue_script( 'particles','https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js', array('jquery'), true); 
  wp_enqueue_script( 'app', get_template_directory_uri() . '/js/app.js', array('jquery'), true); 

}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );

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

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