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

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How To Include Pages In WordPress Tag Queries

Bhagwad Park

Published on: November 7, 2018

Categories: WordPress 2

WordPress’s taxonomy can be pretty confusing. First, we have the default separation between “posts” and “pages”. Then we have categories and tags. In addition, we can have custom post types which opens the door to an endless number of variations.

Figuring out the interactions between the taxonomies can be tricky. For example, by default, “pages” on WordPress cannot be assigned categories or tags. The necessary slot for assigning them is simply missing as shown here:

No Tag Side Widget for Pages

In this article, I will show you two things:

  1. How to Assign tags to Pages as well as Posts
  2. How to make Pages show up in the tag archives

Step 1: Ensuring that We Can Assign Tags to Pages

This fix is a relatively simple one. Open up your functions.php or custom PHP plugin and paste the following code at the bottom. In case you don’t know how to do this, read my comprehensive guide on adding code snippets to WordPress.

// add tag support to pages
function tags_support_all() {
	register_taxonomy_for_object_type('post_tag', 'page');
}
add_action('init', 'tags_support_all');

This simple snippet uses the “register_taxonomy_for_object” function to include “page” in the “post_tag” taxonomy. Once you’ve saved and verified your changes, you’ll see a new widget on the right-hand side of the WordPress editor when you create or edit a page:

New Tag Widget for Pages

That’s all there is to it! Now you can assign tags to pages. But our work isn’t done.

Step 2: Display Pages in the WordPress Tag Archives

It sounds weird, but the default tag archive doesn’t display all post types. So even though we’ve configured pages to have “tags” assigned to them, they won’t actually display in any tag archive. For example, here’s a screenshot of the “tag” archive on my test site:

Page Still Doesn't Show in Default Tag Archives

This archive for the “tech” tag is missing the page on which I just added a new tag of “tech”. To fix this problem, we need to configure WordPress so that the query is modified when requesting a tag.

As before, enter the following code in your WordPress installation:

// 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');
}
add_action('pre_get_posts', 'tags_support_query');

The “pre_get_posts” filter is called whenever WordPress is about to make a call for posts. If it detects that we’re requesting a tag page, it alters the query so that the “post_type” is set to “any”. That includes pages, and any other custom post types that might have tags assigned to them.

Once this code is saved, our tag archive now displays all the posts and pages with a particular tag as it should like this:

Page with Tags Displayed in Archives

Tying it All Together

So now that we’ve done this, let’s say we want to display a list of posts and pages on the sidebar that shares the same tags as the current post. I personally use a plugin called “List Category Posts”. You can download and install it from the WordPress plugin repository here.

While the name suggests that it only displays a list of posts based on category, there is an attribute that allows it to read the tags as well. Here’s the shortcode snippet that I use on my own sidebar:

[catlist currenttags="yes" post_type="page,post" numberposts=5 excludeposts=this]

As you can see, I explicitly need to include the “page” post type in the shortcode for it to trigger a list of pages along with the posts. The “currenttags” attribute gets a list of tags from the displayed pages and uses them to create a query. I also exclude the existing post for obvious reasons.

All in all, this is a comprehensive solution to displaying a list of posts and pages on your sidebar based on a current tag. The code snippets in this article are crucial to enabling this functionality.

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!

Related Posts

What Is Self-Hosted WordPress?

In this post, we’ll differentiate self-hosted WordPress from WordPress.com, and discuss the benefits of the former.

How To Start A Newsletter In WordPress

Check out our complete guide on why and how you should start your own newsletter in WordPress.

Joomla vs. WordPress: Which One Is Better?

In this post, we’ll consider five differences between Joomla and WordPress and how you might go forward with setting up a WordPress website.

How to Eliminate Render-Blocking Resources in WordPress (& Why You Should)

Many things can slow down your site, including render-blocking resources. These are CSS and JavaScript files that delay the loading of content on your site. As a result, visitors will have to wait longer to interact with your page, which could lead to frustration and instant exits.  So, what can you do to eliminate render-blocking […]

Reader Interactions

Comments

  1. gwen says

    November 27, 2020 at 9:08 am

    Hello, thank you for this article which allowed me to remove a plugin to add tags in the pages. Now I would like to know how to display the tags in the pages (they do not display)? Have you made an article about it? Thanks again and congratulations for your work

    Reply
  2. Alex says

    November 6, 2024 at 6:18 am

    Thank you for this article, it was key to helping me include tagged pages in archives and other tag related queries usually reserved only for posts.

    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

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

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
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • 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
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

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