InfoHeap
Tech tutorials, tips, tools and more
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Wordpress beginner tutorials

  • Getting started with wordpress and some useful plugins
  • How to add tag and category to wordpress pages
  • How to become Google verified author of your wordpress blog using Google+ profile
  • How to handle permanent redirects in wordpress
  • How to write custom css in wordpress
  • Using ssh sftp updater support for updating wordpress plugins and themes
  • Wordpress - how to display code from a file in textarea
  • Wordpress - how to make a post sticky on home page
  • Wordpress themes for beginners worth considering
 
  • Home
  • > Tutorials
  • > Wordpress
  • > Wordpress beginner

How to add tag and category to wordpress pages

By admin on Sep 12, 2015

Using wordpress tag and category is a handy way to browse various posts by tag name. WordPress supports browsing all posts for a specific tag at url /tag/TAGNAME and for category at url /category/CATEGORYNAME. By default wordpress does not support tagging pages. This can be easily enabled by installing and activating a relevant wordpress plugin. One such good plugin is post-tags-and-categories-for-pages.

In case you want to have more control (e.g. better control over post_type, etc.) you can easily create your own custom plugin. Here are the steps for doing do:

Enable taxonomy for pages

To enable tag widget in admin interface register_taxonomy_for_object_type API can be used with admin_init hook. Here is the plugin code for this:

function enable_taxonomies_for_pages() {
  register_taxonomy_for_object_type('post_tag', 'page');
  register_taxonomy_for_object_type('category', 'page');
}
add_action('admin_init', 'enable_taxonomies_for_pages');

Once this plugin code is in effect, here is how this widget will appear in admin interface:
wordpress-admin-tag-widget

Include pages in tag/category browse

For including wordpress pages in tag/category browse pages, custom plugin code can use the hook pre_get_posts and sets the ‘post_type’ to array('page', 'post'). Here is the plugin code for this:

function pre_get_posts_taxonomy_archive($query) {
  if ($query->get('tag') || $query->get('category_name')) {
    $query->set('post_type', array('post', 'page'));
  }
}
add_action('pre_get_posts', 'pre_get_posts_taxonomy_archive');

You can combine all the code mentioned in this article and add it to the custom plugin code for your blog.

Suggested posts:

  1. How to include wordpress pages in archives
  2. Meta robot noindex, follow for wordpress tags and category pages
  3. How to show wordpress pages on front page with skip_home custom field
  4. How to hide a post from home and RSS feed in wordpress
  5. How to write custom php in wordpress
  6. WordPress – exclude specific posts from archive pages
  7. How to customize wordpress rss feed
  8. How to setup wordpress custom query params with pretty url format
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Tutorials, Wordpress, Wordpress beginner

Follow InfoHeap

facebook
twitter
googleplus
  • Browse site
  • Article Topics
  • Article archives
  • Recent Articles
  • Contact Us
  • Omoney
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries

Copyright © 2023 InfoHeap.

Powered by WordPress