Skip to content

Instantly share code, notes, and snippets.

@salcode
Last active January 13, 2021 21:37
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 salcode/f254267c7b2f57364f7c2929d699a856 to your computer and use it in GitHub Desktop.
Save salcode/f254267c7b2f57364f7c2929d699a856 to your computer and use it in GitHub Desktop.
<?php
/**
* The code to register a WordPress Custom Post Type (CPT) `fe_recipe`
* with a custom Taxonomy `fe_recipe_tag`
* @package fe_recipe
*/
add_action( 'init', 'fe_recipe_cpt' );
/**
* Register a public CPT and Taxonomy
*/
function fe_recipe_cpt() {
// Post type should be prefixed, singular, and no more than 20 characters.
register_post_type( 'fe_recipe', array(
// Label should be plural and L10n ready.
'label' => __( 'Recipes', 'fe_recipe' ),
'public' => true,
'has_archive' => true,
'rewrite' => array(
// Slug should be plural and L10n ready.
'slug' => _x( 'recipes', 'CPT permalink slug', 'fe_recipe' ),
'with_front' => false,
),
// Add support for the new block based editor (Gutenberg) by exposing this CPT via the REST API.
'show_in_rest' => true,
/**
* 'title', 'editor', 'thumbnail' 'author', 'excerpt','custom-fields',
* 'page-attributes' (menu order),'revisions' (will store revisions),
* 'trackbacks', 'comments', 'post-formats',
*/
'supports' => array( 'title', 'editor', 'custom-fields' ),
// Url to icon or choose from built-in https://developer.wordpress.org/resource/dashicons/.
'menu_icon' => 'dashicons-feedback',
) );
register_taxonomy(
'fe_recipe_tag',
'fe_recipe',
array(
// Label should be plural and L10n ready.
'label' => __( 'Recipe Tags', 'fe_recipe' ),
'show_admin_column' => true,
'rewrite' => array(
// Slug should be singular and L10n ready..
'slug' => _x( 'recipe-tag', 'Custom Taxonomy slug', 'fe_recipe' ),
),
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment