You are currently viewing Link css and js file to wordpress page templates only

Link css and js file to wordpress page templates only

WordPress provides template structure to customize web page as per our requirements. For customizing a page template it’s needed to add some css and js file only to that template page. Use below code a add any css and js file based on page template.

function add_style_and_script_rings(){
    if ( is_page_template('template-data') ) {

    	wp_enqueue_script( 'sldr1-script', site_url().'/wp-includes/js/jquery/ui/widget.min.js');

 	wp_enqueue_script( 'sldr2-script', site_url().'/wp-includes/js/jquery/ui/mouse.min.js');

	wp_enqueue_script( 'sldr3-script', site_url().'/wp-includes/js/jquery/ui/slider.min.js');

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

	wp_enqueue_script( 'product_js', get_stylesheet_directory_uri() . '/js/product.js', array( 'jquery' ), '1.0', true );

    } 
}

add_action('wp_enqueue_scripts','add_style_and_script_rings');

Leave a Reply