Topics Taxonomy Shared by Posts and Pages
Registers a "Topics" taxonomy used by both posts and pages, so related content of either kind can be grouped and listed together.
Opens WPIDE on
Code
add_action( 'init', function () {
register_taxonomy( 'content_topic', array( 'post', 'page' ), array(
'labels' => array(
'name' => 'Topics',
'singular_name' => 'Topic',
'menu_name' => 'Topics',
'all_items' => 'All Topics',
'edit_item' => 'Edit Topic',
'view_item' => 'View Topic',
'update_item' => 'Update Topic',
'add_new_item' => 'Add New Topic',
'new_item_name' => 'New Topic Name',
'search_items' => 'Search Topics',
'not_found' => 'No topics found.',
'parent_item' => 'Parent Topic',
),
'hierarchical' => true,
'public' => true,
'rewrite' => array( 'slug' => 'topic', 'with_front' => false ),
'show_admin_column' => true,
'show_in_rest' => true,
) );
} );
Notes
Add your custom post types to the list to group them too.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.