kaloyanivanov
5/5/2017 - 8:09 PM

Register custom taxonomy for pages

Register custom taxonomy for pages

/*
 *  Register custom taxonomy for pages
 */


add_action( 'admin_menu', 'my_page_excerpt_meta_box' );

function my_page_excerpt_meta_box() {
	add_meta_box( 'postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'page', 'normal', 'core' );
}

register_taxonomy( 'pagecat', 'page', array( 'hierarchical' => true, 'label' => 'Page Category', 'query_var' => true, 'rewrite' => true ) );

add_action( 'admin_menu', 'my_page_taxonomy_meta_boxes' );

function my_page_taxonomy_meta_boxes() {
	foreach ( get_object_taxonomies( 'page' ) as $tax_name ) {
		if ( !is_taxonomy_hierarchical( $tax_name ) ) {
			$tax = get_taxonomy( $tax_name );
			add_meta_box( "tagsdiv-{$tax_name}", $tax->label, 'post_tags_meta_box', 'page', 'side', 'core' );
		}
	}
}