Categories and Tags are not by default supported in WordPress themes, but if you want to support Categories and Tags in your WordPress theme, open up your functions.php file.
You can add categories and tags to your pages by using the add_meta_box() function. In your functions.php file, insert:
function add_category_box_on_page(){
//add meta box
add_meta_box(‘categorydiv’, __(‘Categories’), ‘post_categories_meta_box’, ‘page’, ‘side’, ‘low’);
add_meta_box(‘tagsdiv-post_tag’, __(‘Page Tags’), ‘post_tags_meta_box’, ‘page’, ‘side’, ‘low’);
add_action(‘save_post’, ‘page_cats_tags_save_postdata’);
}
This function adds both category and tags by using the same names (such as ‘tagsdiv-post_tag‘ and ‘categorydiv‘ ) that other WordPress functions use to make sure that the metaboxes that were created with the add_category_box_on_page() function that we created above. The ‘post_categories_meta_box‘ and ‘post_tags_meta_box‘ are used to render the meta boxes because they are native wordpress functions.
After inserting the add_category_box_on_page() function, insert:
add_action(‘admin_menu’, ‘add_category_box_on_page’);
This inserts the Category and Tag boxes onto the Page Editor. Next, add:
function page_cats_tags_save_postdata( $post_id ) {
$wpnj_post_type = $_POST['post_type'];
if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ){
}else{
// Check permissions
if ( ‘page’ == $wpnj_post_type ) {
if ( current_user_can( ‘edit_page’, $post_id ) ){$wpnj_post_cats = array();
foreach($_REQUEST['post_category'] as $key=>$val){
$wpnj_post_cats[] = $val;
}
wp_set_post_categories( $post_id, $wpnj_post_cats );
}
}
}
}
The page_cats_tags_save_postdata( ) function saves the categories and tags selected with the $post_id.
Here is the entire code to insert into your functions.php to get categories and tags on your pages:
function add_category_box_on_page(){
//add meta box
add_meta_box(‘categorydiv’, __(‘Categories’), ‘post_categories_meta_box’, ‘page’, ‘side’, ‘low’);
add_meta_box(‘tagsdiv-post_tag’, __(‘Page Tags’), ‘post_tags_meta_box’, ‘page’, ‘side’, ‘low’);
add_action(‘save_post’, ‘page_cats_tags_save_postdata’);
}add_action(‘admin_menu’, ‘add_category_box_on_page’);
function page_cats_tags_save_postdata( $post_id ) {$wpnj_post_type = $_POST['post_type'];
if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ){
}else{
// Check permissions
if ( ‘page’ == $wpnj_post_type ) {
if ( current_user_can( ‘edit_page’, $post_id ) ){$wpnj_post_cats = array();
foreach($_REQUEST['post_category'] as $key=>$val){
$wpnj_post_cats[] = $val;
}
wp_set_post_categories( $post_id, $wpnj_post_cats );
}
}
}
}







