Backwards Compatibility For Site Icons In WordPress 4.3

| Created: August 27th, 2015
WordPress Development No Comments

When WordPress 4.3 was released, it added the ability for users to set a site icon, also known as a favicon, in the Customizer. In the past, users had to either add this manually, through a plugin, or through the theme options (if their theme included this functionality).

In this post, I’m looking at the last of those scenarios. What should theme authors do now that WordPress itself offers the equivalent functionality?

Continue reading

How To Change The WordPress Post Template Via URL Parameter

| Created: July 27th, 2011
WordPress Development 25 Comments

Have you ever wanted to be able to serve up an alternative version of your posts, perhaps tweaking the layout or even the content of the posts? Not all the time, just in certain circumstances?

I’ve had two cases recently where I’ve needed to do this. My solution: to change the post template when a certain URL parameter is added to the URL. Continue reading

How To Delete All Terms In A Taxonomy

Here’s how to delete all the terms in a taxonomy, whether it be category, tags or a custom taxonomy. Most sites will never need to do this – and there are probably better ways to do this – but here’s the code anyway.
Continue reading

Stop Category Pages From Showing No Results Message

WordPress Development 2 Comments

If you have a category page which has no posts, it will normally trigger your theme’s no posts found message. Seems sensible! However, I have an edge case where I don’t want that message displayed.
Continue reading

How To Prevent Category Widget From Using Category Description As Title Attribute

The Categories widget in WordPress uses the category description as the title attribute for the list items displayed by the widget. While this may be great for very short descriptions, it doesn’t make sense when longer descriptions are in use.
Continue reading

WordPress Optimization Myth: Saving Database Calls

WordPress Development 6 Comments

Tonight I read an article on WPTuts+ titled 10 Quick Tips: Optimizing & Speeding Up Your WordPress Site. For the most part it’s a good article with lots of great tips, but there is one tip which is just plain incorrect:

Using a constant instead of get_option('home'); saves a database call.
Continue reading

How To Force An Update To A Borked Plugin

Editorial Note
I originally wrote this post a couple of years ago when my, um… friend, was a little less clever than he is now. In hindsight, I wasn’t sure the technique included here was a good idea, so I never published it. I’m publishing it now just in case it helps anyone and because it was fun to solve. It’s definitely use at your own risk.

So… Let’s just say for a moment, that you borked your plugin by accidentally tagging the whole repo. Never going to happen, right, because we all use deployment scripts, don’t we?

Continue reading

Setting Cookies In WordPress – Trap For Beginners

| Created: September 26th, 2008
WordPress Development 52 Comments

I recently wrote about displaying ads only to search visitors in WordPress. A key part of the technique described is to set a cookie, identifying the visitor as having come from a search engine. It should have been simple, but my PHP setcookie command didn’t appear to work. Continue reading

Clearing The Cache When A Widget Is Saved

| Created: November 30th, 2011
WordPress Development 6 Comments

WP Super Cache has a setting which allows the cache to be cleared when a post is saved. I needed to clear the cache when a widget is saved. It turned out to be surprisingly easy.
Continue reading

Fetch_feed Not Working With URLs Containing & Symbol

| Created: November 30th, 2011
WordPress Development 5 Comments

I recently came across a strange problem with the fetch_feed function in WordPress not working with URLs containing the & symbol. The URL was being passed to fetch_feed via a shortcode parameter, but fetch_feed couldn’t find the feed.
Continue reading

Practical Theme Support For WordPress 3.0 Menus

| Created: June 21st, 2010
WordPress Development 7 Comments

I’ve read quite a few articles on theme support for the new Menu functionality introduced in WordPress 3.0. However, these have all been theoretical rather than practical. I wanted a real life, working example, including support for users on older versions of WordPress. In the end, I wrote it myself.

WordPress Theme developers, listen up! When updating your themes to work with the new menu functionality, you need to make sure that it still works with older versions of WordPress.

Continue reading

Poll – Which WordPress Theme Framework To Use?

| Created: February 27th, 2009
WordPress Development 69 Comments

So far, my WordPress development work has consisted of writing WordPress plugins and occasionally hacking themes. I’ve always said that I wanted to write a WordPress theme from scratch, but never had time to do so. One of my sites is going to need a redesign shortly, so here’s my big opportunity.

However, with the rise of the WordPress theme framework and the limited time available to me, I’ve started thinking that the sensible thing to do is use a theme framework. But which one?

Continue reading

Custom Page Templates – Calling An External CSS File

| Created: March 30th, 2009
WordPress Development 37 Comments

Note: Not long after writing this post, I discovered that the best way to load external CSS files is by using the wp_enqueue_style function. Similarly, the best way to load JavaScript files is by using the wp_enqueue_script function. The method outlined below is not necessary – although it may still be useful for other things to be added to the head section.

Custom page templates are a powerful feature of WordPress that can be used to make pages (not posts) do something different from normal. You can make them do pretty much anything. Obviously, this can greatly increase the flexibility of your site.

Amongst other things, I’ve used custom page templates to create a basic photo wall and a dynamic listing of jobs in China.

However, because of the way most WordPress themes are created, calling an external CSS file from a custom page template is not straightforward. Here, I explain the problem, look at the options and explain how to use ‘plugin functionality’ to overcome the problem.

Continue reading

XAMMPLite Virtual Directory And WordPress Permalinks

| Created: February 22nd, 2009
WordPress Development 16 Comments

When I’m working on WordPress related development (ie themes and plugins), I like to run WordPress locally. This is great for trying things out before it goes live and also lets me squeeze in some development time in on the train!

My web server package of choice is XAMMP Lite, the Apache distribution that contains PHP and MySQL. Works great in general, but I had some problems with WordPress permalinks and XAMMP Lite. Here’s the solution.

Continue reading