Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress | Add a custom "category-style" taxonomy to Pages
<?php
/**
* Add custom Local taxonomies
* This basically lets you create Categories for Pages (similar to what you can do for Posts)
*
* Additional custom taxonomies can be defined here
* http://codex.wordpress.org/Function_Reference/register_taxonomy
*/
function fs_add_local_page_taxonomies() {
// Add new "Local Types" taxonomy to Pages
register_taxonomy('local-type', 'page', array(
// Hierarchical taxonomy (like categories)
'hierarchical' => true,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => _x( 'Local Types', 'taxonomy general name' ),
'singular_name' => _x( 'Local Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Local Types' ),
'all_items' => __( 'All Local Types' ),
'parent_item' => __( 'Parent Local Type' ),
'parent_item_colon' => __( 'Parent Local Type:' ),
'edit_item' => __( 'Edit Local Type' ),
'update_item' => __( 'Update Local Type' ),
'add_new_item' => __( 'Add New Local Type' ),
'new_item_name' => __( 'New Local Type Name' ),
'menu_name' => __( 'Local Types' ),
),
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'local-type', // This controls the base slug that will display before each term
'with_front' => false, // Don't display the category base before "/local-type/"
'hierarchical' => true // This will allow URL's like "/local-type/wordpress/"
),
));
}
add_action( 'init', 'fs_add_local_page_taxonomies', 0 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment