0

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

7
  • check in firebug or chrome tool and see what error are you getting Commented Aug 11, 2016 at 5:44
  • thanks man "ReferenceError: jQuery is not defined })(jQuery);" Commented Aug 11, 2016 at 5:53
  • looks like you have your script tag called before the jQuery script is called, if you share the link it would be easier to fix. Commented Aug 11, 2016 at 5:56
  • wp_enqueue_script('jquery_2.1.4', get_template_directory_uri(). '/js/jquery-2.1.4.min.js', array( 'jquery' ),false); replaca with above the code Commented Aug 11, 2016 at 6:09
  • here is the link github.com/prashanthcraft/wordpress Commented Aug 11, 2016 at 6:11

1 Answer 1

2

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'); 
?>
Sign up to request clarification or add additional context in comments.

5 Comments

thanks, script is loading to the page but the functions are not working
this site on live server or localhost?
this site is in localhost
updated answer as per private chats. above the script is working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.