Simple tips for writing your first WordPress plugin

I just released an update to my first (and only) WordPress plugin, Notify Bar (version 1.1 at the time of this writing), and I realized I didn’t do any kind of post about launching it. That’s fine. It’s a simple little plugin and no big news in itself, but I thought I’d jot down some notes here about what I learned from developing it.

I’ve been working with WordPress for a few years now, and for quite awhile I had wanted to write a plugin. The main reasons it took me awhile were probably similar to what they are for other people:

  • Too busy
  • Wasn’t sure what kind of plugin to make
  • Didn’t know how to write one

As far as being too busy, that’s a personal thing. If you don’t have time, you don’t have time. But if you can find some hours to throw at it, or even some chunks of minutes here and there, these are some things that helped me that might help you too.

Get the book Professional WordPress Plugin Development by Brad Williams, Ozh Richard, and Justin Tadlock. (Thanks to all three of you guys for writing this book). Eventually you’ll want to read the whole thing, because it’s solid all the way through. But to start with, just read the first few chapters (especially Chapter 3) and get rolling.

I tend to feel that learning by doing is the best way, and when it comes to writing code, it seems especially true that we learn to code by writing code. At least that’s true for me. So grab that book, read it for awhile, then sit it on the desk next to you and start coding. When you get stuck, the book along with the plugin development resources on the WordPress Codex (plus various web tutorials and your own persistence) will eventually get you unstuck.

What I found was that I might read something in the book and not understand it, but then after fumbling around with my code for awhile and piecing together some knowledge from tutorials and other blog posts, I would come back to the same chapter in the book and it would make more sense. Sometimes this makes for a slow process, but this is kind of how we figure things out in web design and development, right? The point here is this: if something doesn’t make sense in the book, do some work and go back to it.

Anyway, the other thing I mentioned earlier that held me up before I started trying to write a plugin was needing an idea of what kind of plugin to write. I happened to make a little bar that allows a website owner to put a quick message at the top of his/her website temporarily. There are other plugins that do this kind of thing besides mine, but I had a certain way I wanted it to work so I made my own. I don’t think mine is better than any of the others, just different.

I guess what I would say regarding how to think of a plugin idea would be just to think of something that would make things a little more convenient on your own site and see if you can make it. It doesn’t have to be complex or groundbreaking — mine certainly isn’t. But for me the goal wasn’t to blow anybody’s mind. I just wanted to solve one little problem on my site and learn to write a plugin at the same time. It worked for me and I expect it would work for a lot of people.

The bottom line is writing a WordPress plugin is probably easier than you think. If you are at the point with WordPress where you’re even a little bit comfortable with going in and adding stuff to the functions.php file in your theme, you are unbelievably close to writing a plugin already. This is a bit of an oversimplification, but all you really have to do is go write some functions, tie them to action hooks, add some information about your plugin and the GPL license text and you’ll pretty much have a plugin. Again, I’m oversimplifying, but not by much.

I really do recommend that book, but more importantly, just get in there and start writing code. If you’re like me, it won’t happen overnight, but who cares? It’s not a race. Take your time and enjoy the ride.

2 Comments on Simple tips for writing your first WordPress plugin

  1. Hey Brian,

    So glad you enjoyed our book! Reading posts like this is exactly why I wanted to write this book. It’s so awesome to hear how people like yourself are learning and releasing WordPress plugins!

    Thanks again Brian!

  2. Web Work Garage (Brian) says:

    Hey Brad. Thanks for dropping by and leaving a comment. I expect to be spending a lot more time with the book in the future as I still have a lot to learn. So thanks in advance for that too!

Leave a Comment