- Blogging for Benjamin Competition
- Why I'm Grateful to Work on the Web
- 24 Pull Requests
- Update Downloadable Product's Expiration Date in WooCommere
- Get Lost in the Flow and Work for More Than a Salary
- Why A Plugin's Popularity Matters
- Why You Should (Or Shouldn't) Use Premium Plugins
- WooCommerce Terms & Conditions
- Only Ship to Continental United States with WooCommerce
- Just Talk
- Why I Love Jetpack
- Making Jetpack Better
- Remove Billing Address for Free Virtual Orders in WooCommerce
- Notify Admin of Customer Address Change in WooCommerce
- Open Your Self Up To New Possibilities
- 2013 Resolutions Review
- Create a Community
- Tips for Starting a Community
- The Intent of Goals
- Create The Ultimate Invoicing System Using WooCommerce
- Change From Address in Ninja Forms
- Work With People Who Inspire You
- Contact Form 7 & MailPoet Integration
- Giving Back to The Community
- Adding Fuctionality to Lean Plugins
- Choose Stripe For a Payment Gateway
- A Dip Into Entrepreneurship
- Reward Yourself
- Blogging for Benjamin Plugin
- Blogging for Benjamin Wrap Up
One of the things I knew I wanted to do when I started this Blogging for Benjamin competition was to easily link users on one of those posts to the original post about the competition. That way users know why there's so many posts in December and about one a month in every other month. So I created a plugin to automatically add a message at the top of each of those posts.
What Does it Do?
This plugin quite simply & elegantly adds an informational message at the top of each post. With some fancy logic to calculate which post it is within the series of posts and displays that and a link to the original blog post that announces the competition.
Why Create a Plugin
There are probably a 1/2 dozen different ways to solve this problem but none of them are as clean as writing a plugin.
Manually Add Content in Post
I could have spent probably just as much time as writing the plugin by manually typing in some text at the top of each post. So time wise it was probably a wash but there are so many other advantages. I can easy change the CSS class across all instances or I can add extra CSS classes or add CSS classes within the content. Or if I ever wanted I could completely turn off this functionality with one click. The extra flexibility a plugin offers here is more than worth the extra brain power to write up a plugin.
Why Not Edit Your Theme?
I probably could have saved some time by coming up with some creative use of the WordPress theme template hierarchy. This, just like writing a plugin, gives the developer a huge amount of flexibility but it doesn't give the developer any power when the time comes to switch themes. Users (including myself) never think they'll have to switch themes but honestly why would you want to lock yourself in? If I wanted to switch themes I wouldn't have to do a thing to make this functionality work.
Share This Functionality
Because I didn't include this functionality in some other theme or post content I have the ability to share this code with others. I put this code up on my GitHub profile and shared with other members of the Blogging For Benjamin competition. I hope that they can use it on their sites so it saves them time. There's also the possibility that they add some extra functionality and if they add some extra functionality and send a pull request to me? Perfect – I'd love to take their work and add it to my site.
Creating Site Specific Plugins
We're always told to separate presentation from logic but how often do we actually take the time to do this? Usually with the deadline of a job there isn't any time to come up with an elegant & flexible solution like this. I know in the past when I felt crushed for time I've thrown functionality like this into a
functions.php file or worse I'll put it into the post content or into the theme files. It's actually quite a shame because this little plugin only took me an hour or two to make and now it's as infinitely flexible as I need.
We as developers need to start taking some time out of our day to clearly separate pieces of functionality into specific plugins so we can easy maintain functionality across sites and also so that we maintain a flexible website. It doesn't matter if we think of this up front or after the website is launched. Set aside some time and organize your codebase.
So, so, so very true. Thanks for posting this Patrick!
Very true to a lot of “problems” out there! For me this post in your series is one of the best as it clearly demonstrates a principle with an example plugin. Very well done!
Keep up the good work, Patrick! 🙂
Thanks David! I appreciate that. I mean to create another couple plugins for this site and I’ll make sure to share them when I do. 🙂