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.
In order to minimise the amount of plugins your site uses, here’s a simple function I use to show a post’s featured image in the RSS feed (something WordPress does not do by default).
A quick line of code to ensure that your WordPress content editor will always land on the HTML tab by default. This will ensure that your HTML tags & attributes are never stripped automatically.
When creating web apps, there’s often a need to generate a random password for your users. There are a number of ways to do this, but in needing to do this recently I came up with this very simple function that will generate a password (or other random string) of whatever length you wish.
WordPress shortcodes are a handy way to add standardised or dynamic content to any post or page. Once you have used them for a bit you will start to realise just how powerful they really are. Here is a guide on how to create shortcodes that you (or your clients) can use.
The other day I was working on a project that required me to extract a numeric ID from the current page’s URL. The problem was that the ID could either be at the end of the URL string or in the middle, depending if there were any parameters added on or not. Here is how I worked around the problem by looping through each character of the string.
Whether you are creating a basic website or setting up a feature-rich online store, you are more than likely going to need to send an email or two from your PHP application. There are essentially two main methods for doing this and here they are explained for your reading pleasure.
If you’re using a CMS you can simply find a handy plugin that displays your Twitter feed on your site, but if you’re working in a non-CMS framework then it’s more tricky. Here’s a handy piece of code you can use to get your twitter feed as well as any tweets that mention your name. I have also provided a simple function that uses regex to turn any URLs, hash tags or @mentions in your tweets into clickable links.
I thought it might be useful to occasionally post some basic PHP tips that I wish I had been given when I first started programming. These will feature simple PHP methods that are aimed more at beginners than experienced PHP devs, but they may also serve as handy little reminders for the latter. To start the series I thought I’d give the simplest way to connect to a MySQL database using PHP.
In the past I have seen (and used) many functions in PHP that essentially serve the exact same purpose – they get specific elements from a page URL. They usually use some kind of regular expression to achieve this and are often around 10-15 lines in length. More recently I have discovered that these functions are pointless and have been since the advent of PHP 4.