Ashish Maurya
Ashish Maurya

Reputation: 59

Wordpress: javascript not loading after enqueuing in function.php

Recently i m transfering my site to wordpress and while doing it i m enqueuing javascripts in my wordpress footer through function,php but it not loading in browser .

my function.php codes :

function NewBiz_scripts() {

    wp_enqueue_style( 'style', get_stylesheet_uri() );
    wp_enqueue_script( 'script', get_template_directory_uri() . '/js/main.js', array ('jquery'), NULL ,true);
    wp_enqueue_style( 'animate',get_template_directory_uri() . '/lib/animate/animate.css' );
    wp_enqueue_style( 'animate-min',get_template_directory_uri() . '/lib/animate/animate.min.css' );
    wp_enqueue_style( 'bootstrap',get_template_directory_uri() . '/lib/bootstrap/css/bootstrap.css' );
    wp_enqueue_style( 'bootstrap.min',get_template_directory_uri() . '/lib/bootstrap/css/bootstrap.min.css' );
    wp_enqueue_script('bootstrap-js-bundle' . get_template_directory_uri() . '/lib/bootstrap/js/bootstrap.bundle.min.js',array(),NULL,true);
    wp_enqueue_script('bootstrap-js-min' . get_stylesheet_uri() . '/lib/bootstrap/js/bootstrap.min.js',NULL,true);
    wp_enqueue_script('counterup' . get_template_directory_uri() . '/lib/counterup/counterup.js', NULL, NULL ,true);
    wp_enqueue_script('easing' . get_template_directory_uri() . '/lib/easing/easing.js', NULL, NULL ,true);
    wp_enqueue_script('easing.min' . get_template_directory_uri() . '/lib/easing/easing.min.js' , NULL,NULL , true);
    wp_enqueue_style ('font-awesome' . get_template_directory_uri() . '/lib/font-awesome/css/font-awesome.css');
    wp_enqueue_style ('font-awesome.min'. get_template_directory_uri() . '/lib/font-awesome/css/font-awesome.min.css');
    wp_enqueue_style ('ionicons' . get_template_directory_uri() . '/lib/ionicons/css/ionicons.css');
    wp_enqueue_style ('ionicons.min' . get_template_directory_uri() . '/lib/ionicons/css/ionicons.min.css');
    wp_enqueue_script('mobile-nav' . get_template_directory_uri () . '/lib/mobile-nav/mobile-nav.js',NULL, NULL , true);
    wp_enqueue_script('jquery' . get_template_directory_uri() . '/lib/jquery/jquery.min.js',array () ,NULL ,NULL ,true );
    wp_enqueue_script('jquery_migrate' . get_template_directory_uri() . '/lib/jquery/jquery-migrate.min.js',array() ,NULL ,NULL ,true );



}   

add_action( 'wp_enqueue_scripts', 'NewBiz_scripts' );
?>

<?php
$theme_name_images = get_bloginfo('stylesheet_directory') . '/img/';
?>

only main.js is loading rest not loading .

screenshot DOM

please some one can help me to figure out what i m doing wrong i new to wordpress. thankyou.

Upvotes: 0

Views: 676

Answers (2)

magicbyt3
magicbyt3

Reputation: 153

do you have wp_footer hook called in your theme template?

wp_footer();

it's usually located in the theme footer.php it's required by WordPress wp_enqueue_script because otherwise the place to add the scripts to would be missing.

Best, Sebo

Upvotes: 0

Shaikh Kamran Ahmed
Shaikh Kamran Ahmed

Reputation: 360

jQuery is already inside WordPress so you don't need to add jQuery again and if you are including minified version .min then you don't need to include the full version. I have commented the repeating files. You also made a mistake enqueue where you added . instead of , I have edited your code so try this code. It should work.

function NewBiz_scripts() {

    wp_enqueue_style( 'style', get_stylesheet_uri() );
    wp_enqueue_script( 'script', get_template_directory_uri() . '/js/main.js', array ('jquery'), NULL ,true);
//    wp_enqueue_style( 'animate',get_template_directory_uri() . '/lib/animate/animate.css' );
    wp_enqueue_style( 'animate-min',get_template_directory_uri() . '/lib/animate/animate.min.css' );
//    wp_enqueue_style( 'bootstrap',get_template_directory_uri() . '/lib/bootstrap/css/bootstrap.css' );
    wp_enqueue_style( 'bootstrap-min',get_template_directory_uri() . '/lib/bootstrap/css/bootstrap.min.css' );
    wp_enqueue_script('bootstrap-js-bundle', get_template_directory_uri() . '/lib/bootstrap/js/bootstrap.bundle.min.js',array ('jquery'),NULL,true);
//    wp_enqueue_script('bootstrap-js-min', get_template_directory_uri() . '/lib/bootstrap/js/bootstrap.min.js',array ('jquery'),true);
    wp_enqueue_script('counterup', get_template_directory_uri() . '/lib/counterup/counterup.js', array ('jquery'), NULL ,true);
    wp_enqueue_script('easing', get_template_directory_uri() . '/lib/easing/easing.js', array ('jquery'), NULL ,true);
    wp_enqueue_script('easing-min', get_template_directory_uri() . '/lib/easing/easing.min.js' , array ('jquery'),NULL , true);
//    wp_enqueue_style ('font-awesome', get_template_directory_uri() . '/lib/font-awesome/css/font-awesome.css');
    wp_enqueue_style ('font-awesome-min', get_template_directory_uri() . '/lib/font-awesome/css/font-awesome.min.css');
//    wp_enqueue_style ('ionicons', get_template_directory_uri() . '/lib/ionicons/css/ionicons.css');
    wp_enqueue_style ('ionicons-min', get_template_directory_uri() . '/lib/ionicons/css/ionicons.min.css');
    wp_enqueue_script('mobile-nav', get_template_directory_uri () . '/lib/mobile-nav/mobile-nav.js',array ('jquery'), NULL , true);
//    wp_enqueue_script('jquery', get_template_directory_uri() . '/lib/jquery/jquery.min.js',array () ,NULL ,NULL ,true );
//    wp_enqueue_script('jquery_migrate' . get_template_directory_uri() . '/lib/jquery/jquery-migrate.min.js',array() ,NULL ,NULL ,true );



}   

add_action( 'wp_enqueue_scripts', 'NewBiz_scripts' );
?>

<?php
$theme_name_images = get_bloginfo('stylesheet_directory') . '/img/';
?>

Upvotes: 1

Related Questions