Skip to content

Instantly share code, notes, and snippets.

@Garconis
Last active September 13, 2017 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Garconis/691959a47c76eadcb9f89e6e2fbd06a9 to your computer and use it in GitHub Desktop.
Save Garconis/691959a47c76eadcb9f89e6e2fbd06a9 to your computer and use it in GitHub Desktop.
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