Skip to content

Instantly share code, notes, and snippets.

@atwellpub
Last active June 24, 2021 15:40
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 atwellpub/0b3545423511e50588606654f43edfc9 to your computer and use it in GitHub Desktop.
Save atwellpub/0b3545423511e50588606654f43edfc9 to your computer and use it in GitHub Desktop.
taxonomy registration for CPT
<?php
namespace Example\Register\Taxonomy;
class Profile_Tag {
static $taxonomy_name;
/**
* Initialize Profile_Tag class
*/
function __construct() {
self::$taxonomy_name = 'profile-tag';
self::register_hooks();
}
/**
* Load action hooks & filters
*/
private function register_hooks() {
add_action( 'example/routine/register/taxonomies', array(__CLASS__, 'register_taxonomy' ));
}
/**
* Register Taxonomy
*/
public static function register_taxonomy() {
/* Register Profile Tags Taxonomy */
$labels = array(
'name' => __( 'Tags', 'example' ),
'singular_name' => __( 'Profile Tag', 'example' ),
'search_items' => __( 'Search Profile Tags' , 'example' ),
'popular_items' => __( 'Popular Profile Tags' , 'example'),
'all_items' => __( 'All Profile Tags' , 'example' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Profile Tag' , 'example' ),
'update_item' => __( 'Update Profile Tag' , 'example' ),
'add_new_item' => __( 'Add New Profile Tag' , 'example' ),
'new_item_name' => __( 'New Profile Tag' , 'example' ),
'separate_items_with_commas'=> __( 'Separate Profile Tags with commas' , 'example' ),
'add_or_remove_items' => __( 'Add or remove Profile Tags' , 'example'),
'choose_from_most_used' => __( 'Choose from the most used profile tags', 'example' ),
'not_found' => __( 'No profile tags found.' , 'example'),
'menu_name' => __( '+Tags', 'example' ),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'show_in_menus' => false,
'show_in_nav_menus' => false,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => false
);
register_taxonomy( self::$taxonomy_name , 'example-profile', $args );
}
}
new Profile_Tag;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment