Amy-Mir / inc / enqueue.php
enqueue.php
Raw
<?php

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'understrap_scripts' ) ) {
	/**
	 * Load theme's JavaScript and CSS sources.
	 */
	function understrap_scripts() {
		// Get the theme data.
		$the_theme     = wp_get_theme();
		$theme_version = $the_theme->get( 'Version' );

		$css_version = $theme_version . '.' . filemtime( get_template_directory() . '/css/theme.min.css' );
		wp_enqueue_style( 'understrap-styles', get_template_directory_uri() . '/css/theme.min.css', array(), $css_version );

		wp_enqueue_script( 'jquery' );

		$js_version = $theme_version . '.' . filemtime( get_template_directory() . '/js/theme.min.js' );
		wp_enqueue_script( 'understrap-scripts', get_template_directory_uri() . '/js/theme.min.js', array(), $js_version, true );
		if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
			wp_enqueue_script( 'comment-reply' );
		}
	}
} 


function jrdesign_theme_support() {
    add_theme_support( "title-tag" );
}


function jrdesign_register_styles() {
    wp_enqueue_style("jrdesign_fontawesome", "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css", array(), "1.0", "all");
}

function jrdesign_register_scripts() {    
	wp_enqueue_script( "jrdesign_polyfill", "https://cdn.jsdelivr.net/npm/intersection-observer@0.7.0/intersection-observer.js", array(), null, false );
	wp_enqueue_script( "jrdesign_lazyImages", "https://cdn.jsdelivr.net/npm/vanilla-lazyload@17.3.1/dist/lazyload.min.js", array(), null, true );
	wp_enqueue_script( "jrdesign_gsap", "https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.1/gsap.min.js", array(), null, false );
    wp_enqueue_script( "jrdesign_jquery", "https://code.jquery.com/jquery-3.4.1.slim.min.js", array(), "3.4.1", true);
    wp_enqueue_script( "jrdesign_popper", "https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js", array(), "1.16.0", true);
}

function jrdesign_page_specific_scripts() {
	global $post;	 
	$current_page_ID = $post->ID;
	$booking_page_ID = get_page_by_path( 'booking' )->ID;

    if ( is_front_page() ) {
        wp_enqueue_script( 'jrdesign-script-home', get_template_directory_uri() . '/js/home-bundle.min.js', array(), '1.0.0', true );
    }
	if ( is_home() ) {
		wp_enqueue_script( 'jrdesign-script-posts', get_template_directory_uri() . '/js/posts.min.js', array(), '1.0.0', true );
	}
	if(  $current_page_ID === $booking_page_ID ) {
		wp_enqueue_script( 'jrdesign-script-booking', get_template_directory_uri() . '/js/booking.min.js', array(), '1.0.0', true );
	}
}

add_action( 'wp_enqueue_scripts', 'jrdesign_page_specific_scripts' );


add_action("after_setup_theme", "jrdesign_theme_support");
add_action("wp_enqueue_scripts", "jrdesign_register_styles");
add_action("wp_enqueue_scripts", "jrdesign_register_scripts");
add_action("wp_enqueue_scripts", "understrap_scripts");