I've been using Gist for a while, but only as a way to quickly share snippets of code with people. I've now decided to change that a bit and make better use of the service - as a result I have added all my snippets from this blog to my Gists and I will continue to add even the smallest snippets as I develop them.
After struggling (yet again) with WordPress' non-hierarchical taxonomy UI I decided to write my own solution for modifying the term selection to use checkboxes just like its hierarchical counterpart.
Having a drop down menu for month selection is a relatively common need, but it can be a pain to write from scratch each time. Here's a short snippet that will generate a select input (drop down menu) for all 12 months of the year - the option values will be the month numbers with leading zeros.
If you use links to navigate to other elements on the same page, it's generally a good idea to animate the scrolling so you don't disorientate your users. This snippet will make that easy for you.
It's a common problem with a dozen different solutions - if you've ever needed to add a 'select all' checkbox to a form in order to make your users' lives easier then you'll have searched for a simple way to do it. If you're using jQuery here's a very simple method.
Most WordPress themes come with a few useful widget areas where you can place any widgets you like. Sometimes, however, you need to add your own widget area because the theme you're using doesn't quite cut it. Paste this snippet in your theme's functions.php file to create a new widget area.
When building a plugin that has its own settings page, it's often handy to create a link to the settings page straight from the Plugins list - this saves users the time it takes to find where exactly your plugin appears in the admin menu. Here is a simple code snippet that creates the settings link for you - all you need to do is tell it where to go.
If something goes wrong with your WordPress install due to a faulty plugin or some bad PHP code, it can often be tricky to work out exactly what the issue is an how to fix it. Here are a couple of helpful functions and snippets that you can use to fix a number of WordPress issues.
I recently had to clean up a database table of user data because it had the same email addresses assigned to multiple users. The first step was putting together a query that pulled only the duplicate email addresses and also told me how many times they occurred - this simple query looked something like this.