👋🏼Welcome to my WP-Host blog where I am excited to share my knowledge and expertise on WordPress hosting and website construction tutorials with you. Let’s connect and learn from each other! You can reach me at info@yrshare.com.
Continue to share the wordpress tutorials. WordPress content can be updated in two forms: articles and pages. The basic content editing is the same, but WordPress pages cannot add tags and categories. So in most cases, we update content through articles and rarely use pages. If you use more pages, you can refer to the following methods to add categories and labels to pages.
Table of Contents
Use plugin
Using a plug-in is the easiest way. You can search and download a plugin – Post Tags and Categories for Pages, and then install it. No special settings are required.
Use code
If your wordpress website already uses a lot of plugins, or this plugin is incompatible with your current wordpress version theme, you can try to use code directly to add tags and classification attributes.
The code to share with you is as follows: the content is extracted from the plugin:
//Add tags and categories to Word Press pages
class PTCFP{
function __construct(){
add_action( 'init', array( $this, 'taxonomies_for_pages' ) );
/**
* Make sure that these query modifications do not affect the admin background
*/
if ( ! is_admin() ) {
add_action( 'pre_get_posts', array( $this, 'category_archives' ) );
add_action( 'pre_get_posts', array( $this, 'tags_archives' ) );
} // ! is_admin
} // __construct
/**
* Add "Tags" and "Categories" to "Pages"
*
* @uses register_taxonomy_for_object_type
*/
function taxonomies_for_pages() {
register_taxonomy_for_object_type( 'post_tag', 'page' );
register_taxonomy_for_object_type( 'category', 'page' );
} // taxonomies_for_pages
/**
* Include "pages" in the tag archive
*/
function tags_archives( $wp_query ) {
if ( $wp_query->get( 'tag' ) )
$wp_query->set( 'post_type', 'any' );
} // tags_archives
/**
* Include "pages" in Category Archives
*/
function category_archives( $wp_query ) {
if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
$wp_query->set( 'post_type', 'any' );
} // category_archives
} // PTCFP
$ptcfp = new PTCFP();
Operation method: copy the above code, add it to the functions.php file of the current wordpress theme template, save it, and refresh the background.
Effect
After using a plugin or code to successfully add tags and category attributes to a page, a category and label menu will appear under the page following WordPress. The content is the same as the article. You can also directly assign categories and labels to the page in the quick editing section on the right.
Summarize
Adding categories or tags to wordpress pages is a very niche requirement, generally speaking, it doesn’t make much sense, and it is generally not recommended for everyone to do so. After the website is completed, the most important thing is to update the basic website content, and don’t always worry about some less important functions or details.
The existence of wordpress pages has other more important meanings, such as some more complex design or development, and the pages can be used to design a separate home page or special page.