Make CSS drop-down menus work on touch devices

CSS drop-down menus are very popular on sites with a hierarchy of pages. They let you get to where you want to go without having to navigate the pages in that hierarchy. But pure-CSS menus suffer a problem: touch devices often can't show the drop-down, because they don't have "hover" and clicking on the top level link goes there. This snippet offers a way around that.

MySQL backups emailed via Python, cron and cPanel

In a previous post, I outlined how I got my MySQL database backup emailed to me regularly from my shared hosting server. About a week later, I ditched that method because I wanted to change it to send my backups to GMail, but the email headers made those emails look like spam so GMail was ditching them. Instead, I rewrote the backup script in Python.

Extend notification emails in wp-e-commerce

The wp-e-commerce shopping cart plugin is probably the most popular cart plugin for WordPress, but it isn't always the most easily customised; in fact, theming it can be a nightmare. One little niggle I had to fix recently was that the notification emails don't include relevant purchase information such as which shipping method was selected, or the per-item comments from the purchaser (e.g. a message to be included inside a book flap).

Conditionally disable Pages Children in WordPress

Whilst WordPress might be a very easy tool for managing website content, and is making great inroads into the CMS market, it isn't very convenient for editing large numbers of pages on a very large website. That's where the Pages Children plugin comes to the rescue, breaking the page administration lists down into a nice, manageable hierarchy. But it doesn't play nice with another great WordPress plugin, Role Scoper, which is also likely to be installed on large websites. Hooks to the rescue!

MySQL backups emailed via cron and cPanel

If you have a website hosted by a hosting service, and it uses a MySQL database, and you rely on regular backups of that database, maybe you need to handle that yourself. If the database is small enough, it might just pay to have cron email you a backup of the database periodically, which is easy enough to set up on a hosting account with cPanel as the control panel.

Feature sniffing Internet Explorer

Pretty much all web developers should know by now that browser sniffing is evil. If you don't know why, you should definitely read Richard Cornford's excellent treatise Browser Detection (and What to Do Instead). Feature detection, where you look for the specific feature you want to use, is much safer; taken to the extreme, it can end up like the rather clever Modernizr project. But what if you really do just want to know if your code has the misfortune to be running on IE7?

Filter documents in WordPress media library

The WordPress media library has a few nice features for managing uploaded files. One thing it doesn't do is make it easy to find documents. It makes it easy to filter all the files to list only the images, or video, or even audio files, but not documents like PDFs, Word documents, spreadsheets etc. But adding a Documents link to the media library is just a few lines of code away.

Telling CSS3PIE about dynamic elements

I love CSS3PIE. I love that I can make use of some of the CSS3 niceties like rounded corners and box shadow, and even IE7 and IE8 can keep up with the more modern browsers and not look too shabby. But if you're adding or moving elements around on your page dynamically, e.g. changing something from display:block to display:none and back, sometimes PIE can't keep up and leaves a box shadow in a strange place.

Simple URL cleanser in PHP

There are lots of ways to tidy up a URL to remove "special" characters. Some do more than others, some purport to do a lot but really don't do much. Some, like WordPress' sanitize_title_with_dashes, throw six or more regular expressions and a couple of multi-byte string conversions at your string but don't handle accented characters. Here's a simple one that does convert accented characters.

Minify CSS on the fly

Keeping your website content as small as it can be so that it downloads fast is as important today as it was back in the pre-broadband days, given that you don't know whether your visitors will be accessing your websites via broadband, dialup, or mobile connections. As CSS files grow, it can be as important to minify them to trim the fat as it is for JavaScript downloads. Here's how I do it on-the-fly for CSS.