Skip to content

Custom Taxonomy

Henner S edited this page Mar 27, 2023 · 1 revision
H::register_taxonomy( $taxonomy, $post_type, [$args] )

$taxonomy (string) - Unique name of the Taxonomy. Example: "brand", "city". Don't use these reserved name.

$post_type (string) - Where to attach this taxonomy to.

$args (array - optional) - Available arguments are:

  • label (string) - Custom display name in admin panel. Default is $name capitalized.

  • slug (string) - Base URL for taxonomy page, cannot be the same as existing post type. Default is the same as $name.

IMPORTANT: Every time you add / change taxonomy, visit "Settings > Permalink" in WP Admin to clear the cache.

Example

BASIC

Registering brand taxonomy to product post type:

H::register_taxonomy( 'brand', 'product' );

Edje WordPress - Custom Taxonomy

CHANGE LABEL & SLUG

H::register_taxonomy('brand', 'product', [
  'label' => 'The Brand',
  'slug' => 'b'
] );

With the snippet above, the admin label will say "The Brand" and the URL for taxonomy page will be /b/brand-name instead of /brand/brand-name.

Clone this wiki locally