Play nice with others. Something to always remember when building a WordPress Plugin.
Something that I always forget to do when building a website, is to check for any conflicts. Either between plugins, themes, scripts or images. Sometimes I forget that when you wp_enqueue a script to the front end, it’s going to be on every page unless you specify what page it should be. Well this happened to me last week. Worst part is that I didn’t even catch it until last night. Then I was up until 4 am fixing the problem. For those of you who know me, 4 am used to be nothing. I laughed in the face of 4 am. Now I’m working on a new schedule and trying to be in bed by 11. So 4 am was a nightmare. Regardless, I solved my problems by remembering to check inside WordPress to see if my plugin plays nice with others.
jQuery Items. They’re All Boys!
One of the best pieces of advice that I ever received, vis-a-vis programming and programming languages, is that all of the elements in jQuery are all boys. Meaning that they all have some kind of a relationship with one another. So when I style an accordion to have a background that’s blue, unless I’m very specific in my css, all accordions will have the same background color, or even worse. All jQuery elements could have that background. That’s exactly what happened to me. Let me explain. I’m a huge fan of the jQuery Themeroller. It’s one place I can go to and style all of my jQuery elements. As long as I use it right, no matter where I use a jQuery accordion or jQuery tabs, all of my jQuery elements have style to them. That’s awesome for the front end of a site. For the backend of a WordPress site, that can be a nightmare.
Here’s Where Things Go Crazy
It turns out that a lot of plugins use accordions and tabs from jQuery. Since I was including my ThemeRoller script, I totally styled everyone’s plugin to look like mine. Which kind of gave me a rad idea for a plugin. Anyways, I figure out how to use the code in the right way and now my stylesheet and scripts only que on my own admin page. Amazing.
Make sure, when you develop your own WordPress Plugin, you’re making sure that you are playing nice with others!