Prashanth Prashanth - 2 months ago 9
jQuery Question

Script is not working in WordPress site

I was creating a WordPress theme using a Bootstrap template. While creating it the scripts are not working in WordPress theme.

I added the script files in the

functions.php
file using the
wp_enqueue_script
. And I inspect it using the
firebug
the script files are loaded in the
footer
. But the script functions are not working (like slider,carousel,etc..,) in the theme.

Here is my
functions.php
code

function royaal_enqueue(){
wp_enqueue_script('jquery_2.1.4', get_template_directory_uri(). '/js/jquery-2.1.4.min.js', array( 'jquery' ),true);
wp_enqueue_script('move-top', get_template_directory_uri(). '/js/move-top.js', array( 'jquery'),true);
wp_enqueue_script('easing', get_template_directory_uri(). '/js/easing.js', array( 'jquery'),true);
wp_enqueue_script('wmuSlider', get_template_directory_uri(). '/js/jquery.wmuSlider.js', array( 'jquery'),true);
wp_enqueue_script('flexslider', get_template_directory_uri(). '/js/jquery.flexslider.js', array( 'jquery'),true);
wp_enqueue_script('bootstrap', get_template_directory_uri(). '/js/bootstrap.js', array( 'jquery'),true);
wp_enqueue_script('custom', get_template_directory_uri(). '/js/custom.js', array( 'jquery'),true);
wp_enqueue_script('easyResponsiveTabs', get_template_directory_uri(). '/js/easyResponsiveTabs.js', array( 'jquery'),true);
wp_enqueue_script('devrama', get_template_directory_uri(). '/js/jquery.devrama.slider-0.9.4.js', array( 'jquery'),true);
wp_enqueue_script('lightCarousel', get_template_directory_uri(). '/js/jquery.light-carousel.js', array( 'jquery'),true);
wp_enqueue_script('jzBox', get_template_directory_uri(). '/js/jzBox.js', array( 'jquery'),true);
}
add_action('wp_footer', 'royaal_enqueue', 999 );


Here is the GitHub link for the code

https://github.com/prashanthcraft/wordpress

vel vel
Answer Source

try this

<?php 
function royaal_enqueue(){
    wp_enqueue_script('jquery_2.1.4', get_template_directory_uri(). '/js/jquery-2.1.4.min.js',array( 'jquery'),true);   
    wp_enqueue_script('move-top', get_template_directory_uri(). '/js/move-top.js', '','',true);
    wp_enqueue_script('easing', get_template_directory_uri(). '/js/easing.js', '','',true);
    wp_enqueue_script('wmuSlider', get_template_directory_uri(). '/js/jquery.wmuSlider.js', '','',true);
    wp_enqueue_script('flexslider', get_template_directory_uri(). '/js/jquery.flexslider.js', '','',true);
    wp_enqueue_script('bootstrap', get_template_directory_uri(). '/js/bootstrap.js', '','',true);
    wp_enqueue_script('custom', get_template_directory_uri(). '/js/custom.js', '','',true);
    wp_enqueue_script('easyResponsiveTabs', get_template_directory_uri(). '/js/easyResponsiveTabs.js', '','',true);
    wp_enqueue_script('devrama', get_template_directory_uri(). '/js/jquery.devrama.slider-0.9.4.js', '','',true);
    wp_enqueue_script('lightCarousel', get_template_directory_uri(). '/js/jquery.light-carousel.js', '','',true);
    wp_enqueue_script('jzBox', get_template_directory_uri(). '/js/jzBox.js', '','',true);
}
add_action('wp_enqueue_scripts', 'royaal_enqueue',999 );

function royaal_custom_js_setting() { ?> 

    <script> 

        jQuery(document).ready(function($) { 
            $(".scroll").click(function(event){ 
            event.preventDefault(); 
            $('html,body').animate({scrollTop:$(this.hash).offset().top},1000); 
        }); 
        }); 

        //Page active Jquery 
        $(function(){ 
            var pgurl = window.location.href.substr(window.location.href.lastIndexOf("/")+1); 
            $(".nav li a").each(function(){ 
            if($(this).attr("href") == pgurl || $(this).attr("href") == '') 
                $(this).parent().addClass("active"); 
            }) 
        }); 

        <!-- FlexSlider --> 
        $(window).load(function(){ 
            $('.flexslider').flexslider({ 
                animation: "slide", 
                start: function(slider){ 
                    $('body').removeClass('loading'); 
                } 
            }); 
        }); 

        $('.example1').wmuSlider(); 


        $(document).ready(function() { 
            $().UItoTop({ easingType: 'easeOutQuart' }); 
        }); 
    </script> 

<?php } 
    add_action('wp_footer','royaal_custom_js_setting'); 
?>