How to load script/css on custom page template in WordPress?

Hello friends, welcome to my another blog how to load script/CSS on the custom page template in WordPress. If you find how to add custom page template dependent js script or CSS stylesheet in WordPress then you are an incorrect page. In WordPress, sometimes we need to add additional js or CSS file into our theme page. For doing that add the below code into your theme functions.php.

Load Additional Scripts on custom page template in WordPress




add_action('wp_enqueue_scripts','load_custom_script');
function load_custom_script(){
    if ( is_page_template('template_custom.php') ) {
        wp_enqueue_script('my-script', get_template_directory_uri() .'/js/map/gmap3.js'); // Your Custom js file
       wp_enqueue_script('my-scripts', get_template_directory_uri() .'/js/my_custom_js.js'); // Your Custom js file
    } 
}

Load Additional Styles on custom page template in WordPress

add_action('wp_enqueue_scripts','load_custom_style');
function load_custom_style(){
     if ( is_page_template('template_custom.php') ) {
	wp_enqueue_style( 'main', get_template_directory_uri() . '/css/main.css'); // Your Custom css file	 	
        wp_enqueue_style( 'mediaelementplayer', get_template_directory_uri() . '/css/mediaelementplayer.css');	// Your Custom css file		
	}
}

Now you know how to load script/CSS on the custom page template in WordPress. I hope the above codes will help you to load script/CSS on the custom page template in WordPress. If you face any problems please comment below.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •