artemsemkin

Rubenz Theme: enqueue custom JS

Jan 6th, 2022 (edited)
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1. add_action( 'wp_enqueue_scripts', 'dequeue_and_then_enqueue', 60 );
  2. function dequeue_and_then_enqueue() {
  3.   // unload parent theme frontend
  4.   wp_deregister_script( 'rubenz-components' );
  5.   wp_dequeue_script( 'rubenz-components' );
  6.  
  7.   $enable_ajax               = get_theme_mod( 'enable_ajax', false );
  8.   $gmap                      = get_option( 'arts_gmap' );
  9.   $main_script_deps          = array( 'modernizr', 'jquery', 'isotope', 'imagesloaded' );
  10.   $main_script_version       = wp_get_theme()->get( 'Version' );
  11.   $ajax_load_missing_scripts = get_theme_mod( 'ajax_load_missing_scripts', false );
  12.  
  13.   // Force load Google Maps script
  14.   // on all the pages with AJAX turned on
  15.   if ( $enable_ajax && ! $ajax_load_missing_scripts && isset( $gmap['key'] ) && ! empty( $gmap['key'] ) ) {
  16.     wp_enqueue_script( 'googlemap', '//maps.googleapis.com/maps/api/js?key=' . $gmap['key'], array(), null, true );
  17.     $main_script_deps [] = 'googlemap';
  18.   }
  19.   // Force load Elementor assets
  20.   // on non-Elementor pages with AJAX turned on
  21.   if ( class_exists( '\Elementor\Frontend' ) && ! arts_is_built_with_elementor() && $enable_ajax ) {
  22.     \Elementor\Frontend::instance()->enqueue_scripts();
  23.   }
  24.   if ( $enable_ajax ) {
  25.     wp_enqueue_script( 'barba', ARTS_THEME_URL . '/js/barba.umd.min.js', array( 'jquery' ), '2.0.0', true );
  26.     $main_script_deps [] = 'barba';
  27.   }
  28.   if ( ! arts_is_elementor_feature_active( 'e_optimized_assets_loading' ) || arts_is_blog_page() ) {
  29.     wp_enqueue_script( 'swiper', ARTS_THEME_URL . '/js/swiper.min.js', array( 'jquery' ), '4.4.1', true );
  30.     $main_script_deps [] = 'swiper';
  31.   }
  32.  
  33.   // load child theme custom frontend from /rubenz-child/js/components.js
  34.   wp_enqueue_script( 'rubenz-components', get_stylesheet_directory_uri() . '/js/components.js', $main_script_deps, $main_script_version, true );
  35. }
  36.  
Add Comment
Please, Sign In to add comment