• Resolved CodeBotics

    (@codebotics)


    I’m slowly but surely building a WordPress theme, but I’ve run into a problem.

    I’m trying to install flexslider which uses jQuery, but I can only get it to work using the normal <script src=”google jQuery url”/>, not using the built in WordPress jQuery. Here’s the important bit of header.php:

    <?php wp_enqueue_script('jQuery'); ?>
    <link rel="stylesheet" href="<?php bloginfo('template_url')?>/css/flexslider.css" type="text/css">
    <script src="<?php bloginfo('template_url')?>/scripts/jquery.flexslider.js"></script>
    <script type="text/javascript" charset="utf-8">
    jQuery(document).ready(function($) {
      $('.flexslider').flexslider({
        animation: "slide"
      });
    });
    </script>
    <?php wp_head();?>

    Thanks in advance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Without really delving into it, you don’t use $.something and jQuery.something together. In your example it would be:

    jQuery(document).ready(function() {
      jQuery('.flexslider').flexslider({
        animation: "slide"
      });
    });

    Check out: This article

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Do this instead.

    <link rel="stylesheet" href="<?php bloginfo('template_url')?>/css/flexslider.css" type="text/css">
    <?php
    add_action('wp_enqueue_scripts','flexslider_enqueue');
    function flexslider_enqueue() {
      wp_enqueue_script('jquery-flexslider', get_bloginfo('template_url').'/scripts/jquery.flexslider.js', array('jquery') );
    }
    <?php wp_head();?>
    <script type="text/javascript" charset="utf-8">
    jQuery(document).ready(function($) {
      $('.flexslider').flexslider({
        animation: "slide"
      });
    });
    </script>

    Definitely do what Otto said instead.

    Thread Starter CodeBotics

    (@codebotics)

    Brilliant, it worked! Thanks for your help. Could you explain what’s happening here that fixes the problem? Is it because I needed to enqueue the flexslider script?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    No, I did it that way because that’s more or less the right way. Your way would have worked fine, but you had the specific elements in question in the wrong order. It was just simpler to rewrite it to the proper enqueuing method so that the enqueue system could take care of ordering for you.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Can't get wp_enqueue_script('jQuery') to work!’ is closed to new replies.