Skip to content

Instantly share code, notes, and snippets.

@indikatordesign

indikatordesign/functions.php Secret

Created Aug 3, 2018
Embed
What would you like to do?
[DFBM - Register CPT]
<?php
// This is the right way to register your taxonomies to work fine with DFBM
function register_my_cpt()
{
$args = array(
'label' => 'Example CPT',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'example-cpt'),
'query_var' => true,
'menu_icon' => 'dashicons-video-alt',
'supports' => array(
'thumbnail','title', 'editor', 'excerpt','author', 'revisions', 'custom-fields',),
);
register_post_type( 'example-cpt', $args );
} // end register_my_cpt
register_my_cpt();
register_taxonomy(
'example-cpt-cat', // "cat" must anywhere be included in your slug
array( 'example-cpt' ),
array(
'hierarchical' => true,
'label' => 'Categories',
'singular_label' => 'Category',
'rewrite' => array( 'slug' => 'example-cpt', 'with_front'=> false )
)
);
register_taxonomy(
'example-cpt-tag', // "tag" must anywhere be included in your slug
array( 'example-cpt' ),
array(
'hierarchical' => false,
'label' => 'Tags',
'singular_label' => 'Tag',
'rewrite' => array( 'slug' => 'example-cpt', 'with_front'=> false )
)
);
// More infos: https://codex.wordpress.org/Function_Reference/register_taxonomy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment