Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to insert the flexslider.js and theme.js using functions.php. However, it doesn't load the flexslider.js and theme.js files when I view the source file.

I've downloaded the flex slider files and inserted jquery.flexslider-min.js as js/flexslider.js.

Functions.php

// Load the Theme JS
function theme_js() {

    wp_register_script( 'flexslider', get_template_directory_uri() . '/js/flexslider.js', array('jquery'), '', true );
    if( is_page( 'home' ) ) {
        wp_enqueue_script( 'flexslider' );
    }   
    wp_enqueue_script('theme_js',  get_template_directory_uri() . '/js/theme.js', array('jquery'), '', true );

}
add_action( 'wp_enqueue_scripts', 'theme_js' );

Theme.js

jQuery(document).ready(function($) {
    $('.flexslider').flexslider();
});

Scripts from the source file

<script type='text/javascript' src='http://localhost:8888/wp-includes/js/jquery/jquery.js?ver=1.10.2'></script>
<script type='text/javascript' src='http://localhost:8888/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>
share|improve this question
    
You can always override Wordpress' crap and just throw those script tags in your footer.php -- –  rm-vanda Feb 3 at 16:29
    
I agree with vanda. enqueue is good for avoiding duplications and conflicts in libraries, but it is not really necessary. You can just put the script tags in the footer yourself. –  Kai Qing Feb 3 at 16:31
1  
@rm-vanda is completely correct - don't add resource files via PHP, it's one overhead you don't want. Also, I would very much recommend you load Flexslider from a CDN as opposed to using one of your server. –  ninty9notout Feb 3 at 16:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.