0

hi guys im aqeel im trying to implement a slide show in a wordpress site's home page but it not working it simply contains the easyslider1.5.js file which i put in js folder css which of course in css folder. Then i used

wp_register_script( 'slides', get_bloginfo('template_url')."/js/easySlider1.5.js" );
wp_enqueue_script('slides');

not worked then

<script src="<?php echo get_template_directory_uri(); ?>/js/easySlider1.5.js" type="text/javascript"></script>

i also used it with get_bloginfo() but did not work .... okay i am using them before

wp_head();

and the jquery code

<script type="text/javascript">
  $(document).ready(function(){ 
    $("#slider").easySlider({
         auto: true,
         continuous: true 
    });
   });  
</script>

and using it after wp_head();

but slide show is not working..... i am working on a project n i really need your help guys.

1
  • Hi Aqeel. To make it easier to read for people who want to answer or have the same problem: Could you please use code formatting and use upper-/lowercase letters? Thanks. Commented Sep 17, 2012 at 12:53

2 Answers 2

1

There's a reason, why one should use the proper hook, which - in this case - is wp_enqueue_scripts.

Then always keep in mind, that some plugins might require a dependency/are dependent on another Javascript library like jQuery.

Now this example shows you how to enqueue your script

  • With the right path/URI API function
  • With jQuery as dependency
  • With a on-demand-caching version number (file name changes, when file contents changes and prevents browser caching in case of an update).
  • Loads in the footer to speed up page loading

That's the right way of loading a script into a WordPress theme.

function wpse64374_register_slider_script()
{
    wp_enqueue_script(
         'easy-slider'
        ,get_stylesheet_directory_uri()."/js/easySlider1.5.js"
        ,array( 'jquery )
        ,filemtime( get_stylesheet_directory()."/js/easySlider1.5.js" )
        ,true
    );
}
add_action( 'wp_enqueue_scripts', 'wpse64374_register_slider_script' );
2
  • hi kaiser the code u suggested did not work .... i think our codes r righy there is some conflict between jQuery funtions or its loading it from some where else more than once.... well thnx alot for ur reply. Commented Sep 19, 2012 at 14:32
  • @Aqeel "did not work" is no proper problem/error description. Please elaborate. And also: Please go back and rework your question - see comment on question. Commented Sep 19, 2012 at 15:21
0

Put this code in current theme's functions.php file

add_action('wp_enqueue_scripts', 'easyslider_function');
function easyslider_function(){
     if(is_home()){ // assume you want to show slider only Home page. if you set static front page then use  is_front_page() in condition.
         wp_register_script( 'easyslider_js', get_bloginfo('template_url')."/js/easySlider1.5.js" );           
         wp_enqueue_script('easyslider_js');
         echo 'jQuery(document).ready(function(){ jQuery("#slider").easySlider({ auto: true, continuous: true }); });';
     }
    }

FYI: make sure you are using correct id as a slider container.

Hope this code helps you. All the best ;)

6
  • 2
    Use wp_enqueue_scripts not wp_head. Commented Sep 17, 2012 at 12:04
  • actually, according to Aqeel's question may be he wants to use script in header file that's why I used wp_head. Commented Sep 17, 2012 at 12:10
  • Aqeel, if my answer useful for you then vote and accept my answer. thanks Commented Sep 17, 2012 at 12:13
  • As @Joseph already said: wp_head is the wrong hook. Use wp_enqueue_scripts instead. Commented Sep 17, 2012 at 12:54
  • hi techguy ....... thnx alot for ur reply but i think prob is somewhere is conflict of jQuery and i think its getting loaded twice....... well thnx again. im trying to solve the issue. but its still creating prob for me. Commented Sep 19, 2012 at 14:34

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.