Setting Up the Nivo Slider in WordPress

Update: Check out the official Nivo Slider WordPress Plugin

Setting up the Nivo Slider in WordPress is a fairly similar process to setting it up on a normal HTML page. However to do it properly there are a few small differences and methods you should use that are WordPress specific.

Download and Setup

First off download the Nivo Slider and put it in your WordPress theme folder somewhere (for instance in “scripts/nivoslider”). You can put the CSS file in a separate folder if you wish but for simplicity I am just going to leave the contents of the download in the same folder. I’m also assuming here that you have your images in the “images” folder in your theme.

The HTML

Setting up the HTML for the slider is almost exactly the same as doing it in a normal HTML page. Something like the following:

<div id="slider">
	<img src="<?php bloginfo("template_url"); ?>/images/slide_1.jpg" alt="" />
	<img src="<?php bloginfo("template_url"); ?>/images/slide_2.jpg" alt="" />
	<img src="<?php bloginfo("template_url"); ?>/images/slide_3.jpg" alt="" title="This is an example of a caption" />
	<img src="<?php bloginfo("template_url"); ?>/images/slide_4.jpg" alt="" />
</div>

Note that images can have links and captions come from the images “title” attribute. We use the WordPress bloginfo() function to make sure we have the proper path to our images.

The PHP & Javascript

On to the fun part. Here is the code first for you “copy & pasters”.

<!-- Include jQuery -->
<?php wp_enqueue_script('jquery'); ?>
<?php wp_head(); ?>
<!-- Include the Nivo Slider CSS file -->
<link rel="stylesheet" href="<?php bloginfo("template_url"); ?>/scripts/nivoslider/nivo-slider.css" type="text/css" media="screen" />
<!-- Include the Nivo Slider JS file -->
<script src="<?php bloginfo("template_url"); ?>/scripts/nivoslider/jquery.nivo.slider.pack.js" type="text/javascript"></script>
<!-- Set up the Nivo Slider -->
<script type="text/javascript">
jQuery(window).load(function() {
	jQuery('#slider').nivoSlider();
});
</script>

First off we are going to include jQuery the right way by using the WordPress wp_enqueue_script() function. Note that this has to be done before the wp_head() function.

Next we include the Nivo Slider CSS and JS files using the bloginfo() function to ensure the correct paths are used. Remember to alter the paths if the folder structure is different in your theme.

Finally we set up the jQuery script to load the Nivo Slider. Note that we need to use “jQuery” rather than just “$” as jQuery is in “no-conflict” mode. Now you should have a lovely slider on your WordPress site.

Update

Comments are now closed on this post. Please direct all support requests to the Support Forums.

201 Comments

Leave a comment
  1. This is great but I would say it would be better to put the image within a loop so the content can be managed from the backend via posts

    • You can. Use timthumb and manage images through the ‘Custom Fields’ box of the post, with the label of your choosing (default is ‘thumb’). For this site, I used a query that selected the number of images, and from what category the images would come from. Code:

      ID, "$ft_cf_photo", true);
      if ($photo){ ?><a href=""><img src="/scripts/timthumb.php?src=&w=647&h=333&zc=1" alt="" title="" />


    • Here, I posted up how to insert the slider manually for WordPress and control images with the ‘Custom Fields’ input on the posts section. The link:

      http://nielsencreativemedia.com/blog/using-the-nivo-slider-with-wordpress

    • As an update, I just wrote the slider to populate within the loop as well as well as load HTML captions dynamically using WordPress 3.0′s standard functions. Check it out here, let me know what you think.

  2. Andre

    No luck getting this to work on my blog. :) Does it have to be outside the loop?

  3. Script queue can and should be used for third party scripts as well. You register your script with wp_register_script() and set jQuery as dependency. Then queue your script and jQuery will be loaded automagically before it.

    I think there is similar set of function to queue CSS as well.

    By the way glad to see links option added, I believe I inquired about it at early version. Off to try it. :)

  4. nass

    Works perfectly on WordPress 2.9.2

    Thank you so much for this wonderful plugin.

  5. occamite

    I love this slider, very cool. I managed to get it working in WordPress, but I’m not sure where to include my modifications (no nav, only fade, no next/prev buttons, etc.). It worked fine in static html, but I must be missing a bit of php somewhere.

    • It sounds like it’s the options in the actual script your trying to include:

      jQuery(window).load(function() {
      	jQuery('#slider').nivoSlider({
      		effect:'fade',
      		directionNav:false,
      		controlNav:false
      	});
      });
  6. Jared

    WordPress seems to delete the ” from the HTML when I publish the page. Am I missing something?

    • Jared

      Sorry the code item was removed the post. WordPress seems to remove the php code block from the HTML when I publish the page. I am using version 2.9.2. Is this something to do with my server?

      • Hi Jared. WordPress doesn’t let you publish php blocks in your posts. It’s better to just put the HTML in your post or simply hard code the script.

  7. Rachelle

    I’m having problems setting this up…

    I have put the PHP & Javascript code in my header.php, before my “php wp_head()” finction

    Then I pasted the HTML code in my post….

    I’m sure I have missed something here…

    If you could give me some tips that would be great!

    • Hi Rachelle

      If you look at the above code closely only the wp_enqueue_script() function should go before the wp_head() function. Everything else can come afterwards.

      Also make sure your paths match up with your actual files. One more thing to check is that the HTML in your post is outputted the same way as WordPress sometimes cleans up and adds extra HTML.

      • Rachelle

        Thanks…is there a way to use this in different pages, with different photos for each? I have installed php widget from wordpress…but doesn’t seem to be working.

        Thanks so much!

  8. is it possible use ul li rather img?

    • I’m afraid not. The slider is set up to work with links and images only.

      • Hey. I love this slider, it’s amazing. But I need to be able to put a into a side-sliding jQuery – do you know any jQuery that the Nivo-slider works well with?

        Great piece of work. And really cool designed website!

  9. ok, thanks for confirmation. but it would be great if we could. have any plan for the future version?

  10. I’m trying to incorporate your slider into a personal project in WordPress. Everything works fine, except 2 things:

    1. Peformance of the Slice Effects under Firefox is terrible. Works fine on Chrome or Opera.
    2. I can’t get to display the captions for some strange reasons, even tho they are selected to show in the scrip options.

    • Hi Greven. In IE set the following rule to get your slides to show in IE:

      #slider a{
          display:block;
      }

      For the captions are you using the nivo-slider.css file?

  11. Hi Gilbert! Thanks a lot for your fast answer! That indeed fixed it! Oh you’re a visitor to my little blog? That’s awesome.

    Since I integrated your slider into the WordPress Loop and automized it with the WordPress Thumbnails I’m thinking in publishing in the near feature a little tutorial explaining it.

    By the way, great work man. Thanks! :)

    Nuno.

  12. I’ve figured it out why the caption wasn’t showing. I’ll leave if here for future reference. The problem was I was using a tooltip jQuery Extension, normally this type of plugins hide the title attribute so the default browser tooltip doesn’t show. That was the problem. Disabling the Tooltip extension enables the caption on nivo Slider. It had to be the only conflict since I inspected the code and I was not hidding the caption anywhere but on the Page Source the Title in the Links appeared with Display:none.

    I wonder if there is a tooltip extension compatible with nivos, that is, that doesn’t hide the title.

  13. Great slider, Gilbert! Can’t say how much i like it.

    I would love to see a future release that would make it work with DIVs or LIs so we could use it to display featured posts in wordpress installations. Or maybe just some hints in that directions…

    Will donate as soon as I’m able and everyone that appreciates this kind of work should donate too!!!

    Best regards,

    pffmihai

  14. Does there is any wordpress plugin created with this script. I will help if you want to create a plugin using this script.

  15. vatsal jain

    i am a bit of a noob at this and would really appreciate some help! could u please tell me where exactly are we supposed to add the html code which uve specified above ?

  16. The Nivo Slider really is awesome. Thanks so much!

    Is it possible to reduce the speed between the changing images? It would be great to see them a little longer.

    • Thanks. To show the images for longer simply increase the pauseTime setting remembering that 1000 is one second.

      • Hi, I want to edit the time settings so that the images change along with another script I am running to change the text beside it.

        Where would I go to edit the time as the only place I can find ‘pauseTime’ is in the .js file and there are currently no numbers.

        I’m not used to editing Javascript files so any assistance will be great. Thanks.

        • You can change the pauseTime speed when you edit the plugin’s PHP file or go directly to wp-nivo-slider.php to make the change there.

      • jens Christensen

        I tried that:

        effect:”random”,slices:15,animSpeed:500,pauseTime:10000

        But it does not change the time the pictures remain visible before changing.

  17. Is this already tested with wordpress 3.0 beta?
    Can´t get it to work….

  18. RH

    I ran across a couple of issues while implementing this excellent script, so I thought I’d share what I learned to help others.

    The jQuery library included in WordPress as of v2.9.2 is jQuery 1.3.x. This version is not compatible with multiple Nivo Sliders. Since it is necessary to load in jQuery 1.4 or higher to get multiple sliders working, in order to play it safe by WordPress jQuery standards, instead of using wp_enqueue_script(‘jquery’); in the header, refer to the “Load a default WordPress script from a non-default location” section of http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    When implementing your various sliders, change the ID of each DIV to a unique name, and then update your header Nivo setup script and CSS file accordingly.

  19. Love this! I replaced AnythingSlider with this. I felt it suited my site better.
    Check it out in action at my band’s site:
    http://www.findingcore.com

    Something odd happens once in a while though. After it cycles through a couple times, the images break-up and pieces of other images can be seen through the others.

    Any ideas?
    Love it though!

  20. mpmchugh

    Just tried implementing this on a WrodPress side for some homepage marquee images, but found that it interferes with the PixoPoint Menu system, which is an automated SuckerFish menu. The menus initially drop, but then partially disappear when you try to navigate down them. I didn’t have this problem with SlidePress which I used initially, of vSlider, which I replaced it with to go non-flash. I was hoping to use Nivo Slider, which I liked better with it’s navigation and transition options.

    Any idea how to avoid the conflict?

    Thanks,
    Michael

    • mpmchugh

      I found a z-index conflict. Oddly the PixoPoint Menus had a low z-index of 20, which Nivo was also using z-index settings up to 99. I set PixoPoint’s to 200 and all seems fine now.

      -mpm

  21. mpmchugh

    Is there a way to make it not blank out at the end, before cycling to the first image again, and use the last image as the basis for transitioning to the first? It would also be nice if there was a transition to the first image at the beginning, which just seems to blink on rather than fade in or something.

    • mpmchugh

      The blanking out at the end for a sec was an HTML error in my image list, so that’s not an issue, but a transition into the first image would be great.

      -mpm

  22. Steve

    Is there a way to randomize the images in the slideshow?

  23. Tim

    I set this up in WordPress. Works fine in FF and Safari, but images don’t show up in IE. I added your conditional comment {display:block}, although I set it on #slider img as I don’t have the pics linked. Any help is appreciated.

  24. Hi there,

    First of all thanks for this great slider :)
    But I have a problem with the category selection… Can’t we select all the category?
    Well I actually don’t need to specify a categorie, can’t the slideshow feature the thumbnails regardless of the category?

    Thanks for your help!

  25. Anoop D

    Saw the comments on z-index .. but i just tried to get a dropdown menu over nevoslider … it simply doesnt work …. i played with increasing the z-index but the dropdown doesn’t shows in front :( .. it would be a great help if somebody figures what went wrong.

    I used jquery to set up drop down

    jQuery(document).ready(function() {
    // Opera Fix
    jQuery(“.menu li”).hover(function(){
    jQuery(this).find(‘ul:first’).css({visibility: “visible”,display: “none”}).show(268);
    },function(){
    jQuery(this).find(‘ul:first’).css({visibility: “hidden”});
    });
    });

    and made the style

    .menu ul ul li
    {
    z-index:200;
    }

    does anybody know what would have gone wrong

  26. RockableThemes

    Hi Gilbert,
    I’v send you an e-mail with my problem. Could you please read it and help me.
    Thank you.

  27. Thanks for the slider. I am using a theme that came with the Nivo Slider. Works great in FF but in IE the images do not show up. I tried adding the [slider a{ display:block;}] coding but it did not solve the issue. Any help is appreciated.
    btw the theme I am using is the Estrada theme and my website is adaviddance.com

  28. Figured out the IE fix. Had to modify it a little for the theme I was using.

  29. WPsmash

    Hi all,
    So I am trying to implement the slider in wordpress theme. Everething is ok, the css and jquery seams to be redden… but the only problem is that images are not displayed.
    To display images I am using the timthumb script that get the first image from the post, this is the code :

    have_posts()) : $my_query->the_post();$do_not_duplicate = $post->ID;
    ?>

    <a href="”>

    Images are being displayed just when I am deleting this divs but they are displayed just normally without any effect.
    So where could be the problem? Could someone help me?

  30. saurav

    Hi,
    I have implemented all the slider dynamically using wordpress, fetch the images from featured category and its working fine. Now what I want to do is the images thumbnail of images is generated dynamically.Please help me..How I can generate slider image as a thumbnail dynamically?
    Thank you..

Trackbacks for this post

  1. Nivo Slider – jQuery Image Slider | webdemar.com
  2. wp-popular.com » Blog Archive » Setting Up the Nivo Slider in Wordpress | dev7studios
  3. A Wordpress Slider, how to go about adding it to your site | Distort.it
  4. 5 Powerful Resources for Web Designers and Developers | Gadgets World
  5. 5 Powerful Resources for Web Designers and Developers | Gadgets World
  6. Use Nivo Slider for an Awesome WordPress Slider | Deondre Martin Ng
  7. Nivo Slider – jQuery Image Slider- Noticias del Cerebro Digital
  8. Saucy Slideshows « ArtisanTalent Blog
  9. Nivo Slider - Featured Content Slider เรียบ ดูดีมากกกก | kruSAKBlog
  10. ゆっくりと… » iPad風jQueryイメージスライダーをWordPress記事に組み込む
  11. Setting Up the Nivo Slider in WordPress | Dev7studios - Courrier Blog
  12. Nivo Slider, múltiples efectos de transición para tu sitio o WordPress | SummArg
  13. A WordPress Slider, how to go about adding it to your site | Matthew Snider
  14. Nivo Slider Slideshow Jquery
  15. Q&A: Mit slideshowBlogtips.dk | Blogtips.dk
  16. Nivo Slider – The Most Awesome jQuery Image Slider | Web Tutorials
  17. Using HTML Captions with WordPress and the Nivo Slider | Mark Wilkinson on WordPress
  18. Nivo Slider. The Most Awesome Jquery Image Slider | Free Premium Wordpress Themes and Wordpress Templates 2011 by WordpressBling.Com

Comments are now closed for this article.