• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero Blog

NameHero Blog

Web Hosting Tips & Resources From NameHero

  • Hosting
    • Web Hosting
    • VPS Hosting
    • WordPress Hosting
    • WooCommerce Hosting
  • Reseller
  • Enterprise
  • Domains
  • Account
  • Blog Home
  • Categories

How To Add Tags To Pages In WordPress

Bhagwad Park

Published on: March 9, 2020

Categories: WordPress 2

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:

Add Tags to Pages in WordPress
Now you can add tags to pages in WordPress

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?

Bhagwad Park Profile Picture
Bhagwad Park

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!

Reader Interactions

Comments

  1. DH McCarty says

    April 30, 2022 at 3:30 pm

    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.

    Reply
  2. Alan Barnett says

    November 23, 2022 at 11:41 am

    I dont know how to write code. Isnt there an easier way to add tags to pages please?

    Reply

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!

Most Popular Posts

Speed up your site: solving the WordPress slowdown

NameHero’s Recommended WordPress Plugin and Theme Setup (2023)

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • Website Performance
  • Web Hosting
  • Resellers
  • Website Development
  • Website Security
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • Domains
Help & Support
  • NameHero Blog
  • Knowledgebase
  • Announcements
  • Affiliates
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2023 NameHero, LLC. All rights reserved.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA