Categories
Coding

jQuery Nivo Slider + WordPress JavaScript error

I don’t know if you can really call this a bug, but it’s certainly something that needs to be dealt with. After implementing the jQuery Nivo Slider plugin (which is great when it works), I was getting the following error in the JavaScript console in Chrome during every image transition:

Uncaught TypeError: Cannot call method 'substr' of undefined

The transitions were working, but the previous image wasn’t ‘overlayed’ by the next image – it would just disappear and the new one would appear. It was almost like something else was there. Looking back at my ‘raw’ HTML code in the WordPress post, I had all three images in sequential order, but neatly aligned by pressing enter after each. What I didn’t know was that WordPress, even in HTML mode, was adding <br /> tags after I pressed enter, causing this problem.

Solution: Make the <img> tags back to back on the same line, thus removing the automatically generated <br /> tags.