A Bristol Geek

No trees were harmed in the creation of this blog; however, a significant number of electrons were slightly inconvenienced.

Tag and Categorize your WordPress Pages

Wordpress Categories and Tags

Pages can not be tag'd or categorized in WordPress by standard.

WordPress treats posts and pages differently, posts can be tagged and placed into categories. On the other hand pages can not, they can however be given a hierarchy that allows you to create distinct sections to your site. Items with tags or those in categories are displayed in your site’s archives (tag and category respectivly), this way if a visitor wants to find something on a specific topic they can click into the relevent archive.

I decided that I didn’t like this behaviour, so I went and found a way to let me tag my pages and place them into categories. It turned out to be a lot easier that I first expected, just a few simple tweaks to the functions.php page in my theme.

For those of you that have not played with your theme files before and are using a stock theme, don’t worry WordPress gives you the ability to do this from the admin area. The theme editor can be found in “Appearance > Editor”, you then just need to select your “Theme Functions” file and place the code on its own line after the “<?php” tag at the top.

The code you need to insert is as follows:

Once you save the changes you will see the normall Tag and Category pickers in your “Edit Page” area.  All that code has done is tell wordpress to enable “tags” and “categories” for objects (everything in wordpress is an object) that are pages, as posts are already enabled it means that you can now tag and categorize both.

Before your newly tagged and categorized pages will show up in your archives you need to add a few extra lines of code to ensure that wordpress picks up the pages when it displays an archive. Place the following code under the code that you added earlier:

Thats it, now you can treat pages as if they were posts, just posts that can be placed into a hierarchy. Should you make a mistake when you’re editing your theme and you mess up your site there is a quick fix. Just open the functions.php file for your theme via an ftp program and remove your changes.

My standard caviat applies to this article, please please back up your theme before you edit it, and if you make a mistake you can’t hold be liable for any bad things that happen. However if you do make a mistake and want some help fixing it just leave me a comment and I will do everything I can to help!

One thought on “Tag and Categorize your WordPress Pages

  • Chris says:

    I get a error when adding the 2nd block of code. It seems to be something to do with the syntax of line two, unfortunately I’m not clever enough to tell you what. The tags and categories will come in handy though. Thanks

Leave a Reply