简体   繁体   English

将 Css、JS 插件和自定义脚本文件加载到 wordpress

[英]Load Css, JS plugin and Custom Script file into wordpress

Been having a hard time getting this to work... I'm trying to use animation for some transitions on a website I'm working on but when I include the files the average way it breaks the theme... A lot of reading has brought me knowing I need to use functions.php to enqueue the scripts and CSS but I tried and no dice.一直很难让它工作......我正在尝试在我正在工作的网站上使用动画进行一些过渡,但是当我包含文件时,它打破了主题的平均方式......大量阅读让我知道我需要使用functions.php 来将脚本和CSS 排入队列,但我尝试过但没有骰子。

I am using a child theme我正在使用儿童主题

The CSS I need to load is located in a folder my child-theme's directory called "css", the custom js and plugin js I need to load is located in a folder in my child-themes directory called "js".我需要加载的 CSS 位于我的子主题目录中名为“css”的文件夹中,我需要加载的自定义 js 和插件 js 位于我的子主题目录中名为“js”的文件夹中。

1-The CSS needs to be in the header 1-CSS 需要在标题中

2-jQuery needs to load 2-jQuery需要加载

3-The plugin then needs to load 3-插件然后需要加载

4-My scripts.js file needs to load, it manipulates the plugin's settings. 4-我的scripts.js 文件需要加载,它操作插件的设置。

If you still don't understand this then basically I want to use http://git.blivesta.com/animsition/ within a wordpress child-theme.如果您仍然不明白这一点,那么基本上我想在 wordpress 子主题中使用http://git.blivesta.com/animsition/ Thanks.谢谢。

Try reading https://codex.wordpress.org/Child_Themes , it will help you a lot.尝试阅读https://codex.wordpress.org/Child_Themes ,它会对你有很大帮助。

Regarding your question, you have to place the following code in your child's theme functions.php file:关于您的问题,您必须将以下代码放在您孩子的主题functions.php 文件中:

function animsition_enqueue_styles_and_styles() {

    $parent_style = 'parent-style';

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );

    wp_enqueue_style( 'child-style', 
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style )
    );

    wp_enqueue_style( 'animsition-style', get_stylesheet_directory_uri() . '/css/animsition.min.css' );

    wp_enqueue_script( 'animsition-js', get_stylesheet_directory_uri() . '/js/jquery.animsition.min.js',  array('jquery'), '20150628', false );     

    wp_enqueue_script( 'custom-animsition-js', get_stylesheet_directory_uri() . '/js/scripts.js',  array('animsition-js','jquery'), '20150628', false ); 

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

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

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