Last active
March 20, 2019 11:37
-
-
Save amorkovin/e4b155cba0ddc8664bd1b2be3aef31da to your computer and use it in GitHub Desktop.
Загрузка стилей и скриптов WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load css/js | |
add_action( 'wp_enqueue_scripts', 'add_styles_scripts' ); | |
function add_styles_scripts() { | |
# Jquery | |
wp_deregister_script('jquery-core'); | |
wp_register_script('jquery-core', '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'); | |
wp_enqueue_script('jquery'); | |
# css | |
wp_register_style( 'theme-css', get_bloginfo('template_url').'/style.css' ); | |
wp_enqueue_style('theme-css'); | |
wp_register_style( 'theme-fonts', get_bloginfo('template_url').'/fonts.css' ); | |
wp_enqueue_style('theme-fonts'); | |
# slick | |
global $cat_diet_id; | |
$current_cat = get_query_var('cat'); | |
$enqueue_slick = false; | |
if ( is_front_page() ) { | |
$enqueue_slick = true; | |
} elseif ( $cat_diet_id && is_category($cat_diet_id) || cat_is_ancestor_of($cat_diet_id, $current_cat) ) { | |
$enqueue_slick = true; | |
} | |
if ($enqueue_slick) { | |
wp_register_script( 'theme-slick', get_bloginfo('template_url').'/js/slick.min.js', ['jquery'] ); | |
wp_enqueue_script('theme-slick'); | |
} | |
# modal | |
wp_register_script( 'theme-modal', get_bloginfo('template_url').'/js/arcticmodal/jquery.arcticmodal-0.3.min.js', array('jquery') ); | |
wp_enqueue_script('theme-modal'); | |
# likely | |
if ( is_single() ) { | |
wp_register_script( 'theme-likely', get_bloginfo('template_url').'/js/likely/likely.js', ['jquery'] ); | |
wp_enqueue_script('theme-likely'); | |
wp_register_style( 'theme-likely-css', get_bloginfo('template_url').'/js/likely/style.css' ); | |
wp_enqueue_style('theme-likely-css'); | |
} | |
# comments | |
if ( is_singular() && comments_open() && (get_option('thread_comments') == 1) ) { | |
wp_enqueue_script('comment-reply'); | |
} | |
# scripts.js | |
wp_register_script( 'theme-scripts', get_bloginfo('template_url').'/js/scripts.js', ['jquery'] ); | |
wp_enqueue_script('theme-scripts'); | |
# Для плагина | |
wp_register_script( 'morkovin-makeev-youtube-script', plugin_dir_url( __FILE__ ) . 'video.js', array(), null, true ); | |
wp_enqueue_script('morkovin-makeev-youtube-script'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment