It’s always seemed a bit weird to me that WordPress doesn’t extend its taxonomy system to posts. While with posts, you can make use of the extensive category/tag infrastructure and manipulate them in a variety of ways, this same facility doesn’t apply to pages. As a result, we lose out on a lot of conveniences. In this article, I’ll include a short snippet to show you how to add tags to pages in WordPress.
Posts vs Pages – Who Cares?
But first – why this distinction between posts and page? The reasons can be traced back to WordPress’ blogging roots, when the homepage was merely a collection of reverse-chronological posts. During this time, posts were the “meat” of the blog, and pages were just an afterthought. According to the thinking at the time, pages didn’t need classification systems because they served specific purposes, and you wouldn’t want pages showing up in your archives.
This made sense. After all, when someone is viewing an archive, you don’t want your “Contact” page to show up do you? Posts were the only content that mattered, whereas pages serviced specific purposes, and were only included for functional purposes, and not part of the “main” blog.
But WordPress Has Evolved
WordPress now powers close to 30% of the Internet. It’s not just a blogging platform anymore. In fact, for many websites, it’s the posts that are now superfluous! For example, I maintain a small personal website consisting entirely of pages and not a single post. Many corporate websites are exactly like this as well.
Then there are other websites with many, many pages as well as posts. With sites like this, we need a way to implement a coherent taxonomy for pages so that we can sort and categorize them properly.
Pages Have No Comments
One of the big visual differences between posts and pages, is that the later typically don’t allow comments. Of course, you can disable comments on posts as well, but then you get a little notice at the bottom saying, “Comments on this post have been disabled”, or something like that depending on the theme. There are ways to remove this message of course, but that requires adding additional code, and selectively disabling comments on every single post that you want to exclude.
Personally, I prefer to just use pages instead. These are regular posts in every way (perhaps more detailed), but for which I don’t allow comments, because they’re for informational or “landing” pages, and I don’t want anyone commenting on them.
Adding Tags to Pages
For taxonomy purposes, I choose to use tags for pages instead of categories, because I prefer a nice, flat structure, as compared to the hierarchical model of categories. But it could go either way. From a technical standpoint, there’s no difference between the two.
To allow pages to have tags, copy and paste the following code into your functions.php file:
// add tag support to pages
function tags_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');
}
// ensure all pages are included in tag queries
function tags_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any');
}
// tag hooks
add_action('init', 'tags_support_all');
add_action('pre_get_posts', 'tags_support_query');
If you don’t know how to do this, take a look at our tutorial on how to add code to WordPress.
Once you’ve added this code, open up a page for editing and you’ll see that there’s now an option to specify the tags! Here’s a screenshot of what it looks like:
You can see that this is a page from the “Page Attributes” section. You can also see that it doesn’t contain any category expandable area. Just tags. Now you can create archives of related pages by linking them together with specific tags. Easy right?
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!
DH McCarty says
Hello- exploring whether this will work or not for me. I don’t see the entries under plug-in menu you list on the linked page to add code, which makes me suspect this is not an option for certain plans. I have a Pro plan, which tells me at the top of the plug-in page in the WordPress admin area that I must upgrade to install plug-ins. Does your custom approach work in such a case? I could create the plug-in as you suggest in the article, but if I’m blocked from installing it by WordPress, all is for naught unless I upgrade the plan, which I don’t need to do for other purposes. A little more clarity on what the base specs are for this approach to work would be helpful.
Alan Barnett says
I dont know how to write code. Isnt there an easier way to add tags to pages please?