Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
class Eric{
function __construct(){
add_action( 'init', [ $this, 'remove_category_for_posts' ] );
add_action( 'init', [ $this, 'add_category_for_pages' ] );
add_filter( 'register_taxonomy_args', [ $this, 'rename_category' ], 10, 3);
add_action( 'pre_get_posts', [ $this, 'category_archives' ] );
}
function remove_category_for_posts() {
register_taxonomy( 'category', array() );
}
function add_category_for_pages() {
register_taxonomy_for_object_type( 'category', 'page' );
}
function rename_category ( $args, $taxonomy, $object_type ){
if ( 'category' !== $taxonomy ){
return $args;
}
$args['labels'] = array(
'name' => __( 'Categories' ),
'singular_name' => __( 'Category' ),
'search_items' => __( 'Search Categories' ),
'popular_items' => null,
'all_items' => __( 'All Categories' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
'separate_items_with_commas' => null,
'add_or_remove_items' => null,
'choose_from_most_used' => null,
'back_to_items' => __( '&larr; Go to Categories' ),
);
return $args;
}
function category_archives( $query ) {
if( !is_admin() && is_category() ) {
$query->set( 'post_type', 'page' );
}
}
}
$eric = new Eric();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment