How to Add Categories to Pages in WordPress
By default, WordPress has four taxonomies that comes with right after the installation and Category is one of them. Other three taxonomies are Tags, Link Category, and Post Formats. So Category is used to group the contents into the different sections. The Posts in WordPress can be determined by which category they fall in.
For Example, The website may have the categories for Posts filed under Sports, Blog, News, Weather, etc.
When a new post is published, it will be automatically filed under the default category i.e ‘Uncategorized’. If you are an Administrator, you can, however, change the default category from Settings » Writing screen. You can also assign tags for the posts. Remember, a post can have multiple tags.
By default, WordPress only allows users to add categories or tags to Posts only. You may want to add categories to Pages too. Adding just a few lines of codes in your functions.php
will do that. There are also a lot of available plugins in WordPress Repository. But we’ll do the trick without using plugins to add categories to pages in WordPress.
Add the following snippet in your theme’s functions.php
function add_categories_to_pages() { register_taxonomy_for_object_type( 'category', 'page' ); } add_action( 'init', 'add_categories_to_pages' );
To add tags
taxonomy in your page, add the following code in your functions.php
function add_tags_to_pages() { register_taxonomy_for_object_type( 'post_tag', 'page' ); } add_action( 'init', 'add_tags_to_page');
The above Codes will result the below screenshot in your Page in Dashboard
If you want to display Tags or Category for your Custom Post Type, add the following code:
function add_taxonomies_to_cpt() { register_taxonomy_for_object_type('category','custom_post_type'); register_taxonomy_for_object_type( 'post_tag', 'custom_post_type' ); } add_action( 'init', 'add_taxonomies_to_cpt');
Here, replace custom_post_type
with your Custom Post Type.
There are few plugins which can directly add the Category and Tags taxonomies in your Pages, Custom Post Types. Some of them are listed below:
CONCLUSION
Categories, therefore, provide a very useful way to group similar posts together so that the visitors can relate what a post is about. The taxonomy also makes it easier for users to find the content of the site without any hurdle. Categories are much likely to tags but broader. Depending upon the variation of the theme you are using, categories can be displayed anywhere you want within the site. They can be displayed at the top of the posts or bottom. You can display them on your Navigation menu or Widgets. You can assign multiple categories to the posts too.
I hope this article helped you add categories and tags in Pages. If you use categories and tags in Pages, then let others know how you are using them by commenting in the form below.