Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  kaiser Sep 17 '12 at 12:53

2 Answers 2

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 ;)

share|improve this answer
2  
Use wp_enqueue_scripts not wp_head. –  Joseph Sep 17 '12 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. –  techguy4web Sep 17 '12 at 12:10
    
Aqeel, if my answer useful for you then vote and accept my answer. thanks –  techguy4web Sep 17 '12 at 12:13
    
As @Joseph already said: wp_head is the wrong hook. Use wp_enqueue_scripts instead. –  kaiser Sep 17 '12 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. –  Aqeel Sep 19 '12 at 14:34

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' );
share|improve this answer
    
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. –  Aqeel Sep 19 '12 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. –  kaiser Sep 19 '12 at 15:21

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.