Custom Fields for Categories using WordPress

There are endless reasons why it could be helpful to use customs fields on categories pages in WordPress – and it seems many other WP users agree. The users here speak about some plugins that are now out of date – so thankfully, there’s now a painless, fool-proof way to get this working.

1. Download Headspace2

Firstly, you need to download and install the HeadSpace2 SEO plugin. As well as being a mean SEO plugin (far beyond All-In-One or any other plugin you’re probably used to), HeadSpace2 lets you create custom meta data on pages, posts or categories – exactly what we need!

2. Update Page Modules

Once the plugin is activated, navigate to Settings > HeadSpace > Page Modules and drag the Custom Meta into the green Simple box – see below.

3. Add Custom Values

Select the edit box on the right and add the custom fields you’d like to display on your category pages. I’m building an affiliate portal so have added “free-bingo-value”.

4. Edit Categories

The custom fields will now show up on your category description pages – towards the bottom. Add the value you require and update. Here you can also add any of the other modules you selected above – Page Description and Keywords, for example.

5. Call the Custom Fields

Call the custom fields anywhere (see update below) in your theme by using the following PHP code, replacing the custom field name (‘free-bingo-value’) with your own.

<?php echo MetaData::get_custom('free-bingo-value'); ?>

Simple as that! It’ll show up without any styling, but you can place tags around it to display as you require.

Update

I’ve crossed out anywhere because I’ve heard from some folks who couldn’t get it to show up on single pages.

Of course, I realise now why anywhere was far too optimistic! If you’re going to call the custom value on a single page (or anywhere in the post loop), it’s going to look for the ‘free-bingo-value’ custom value for that particular post – not for the category. So stick to pasting this on your archive.php or category.php templates.

Update 2

HeadSpace2 is having some issues with WP3.0 and using the plugin for the purpose above will require one small change.

Open headspace.php from the plugin folder and change all instances of cat_ID to tag_ID. Simple as that! Thanks to Rob Felty for the fix.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>