Skip to content

Instantly share code, notes, and snippets.

@tjtaylo
Last active August 17, 2017 19:01
Show Gist options
  • Save tjtaylo/1c7d044d8df5b703dc73cfbd5b0a3482 to your computer and use it in GitHub Desktop.
Save tjtaylo/1c7d044d8df5b703dc73cfbd5b0a3482 to your computer and use it in GitHub Desktop.
<?php
// variables
$name = 'Products';
$singular_name = 'Product';
$menu_position = 6;
$func_name = 'cpt_' . strtolower($singular_name);
if( !function_exists( $func_name ) ) {
$func_name = function() use ($name, $singular_name) {
register_post_type(
strtolower($singular_name),
array(
'labels' => array(
'name' => $name,
'singular_name' => $singular_name,
'add_new' => 'Add New',
'add_new_item' => 'Add New ' . $singular_name,
'edit' => 'Edit',
'edit_item' => 'Edit ' . $singular_name,
'new_item' => 'New ' . $singular_name,
'view' => 'View',
'view_item' => 'View ' . $singular_name,
'search_items' => 'Search ' . $name,
'parent_item_colon' => 'Parent ' . $name . ':',
'not_found' => 'No ' . strtolower($name) . ' found',
'not_found_in_trash' => 'No ' . strtolower($name) . ' found in Trash',
'parent' => 'Parent ' . $singular_name,
),
'description' => 'Create a ' . $singular_name . '.',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'publicly_queryable' => true,
'exclude_from_search' => true,
'menu_position' => 6,
'hierarchical' => true,
'query_var' => true,
'rewrite' => array(
'slug' => str_replace(' ', '-', strtolower($name))
),
'supports' => array (
'title',
'editor',
'page-attributes'
)
)
);
};
}
add_action( 'init', $func_name );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment