Created
July 6, 2016 18:14
-
-
Save stevenspads/04aac3ad531d162af00b1ebdb52a5d68 to your computer and use it in GitHub Desktop.
WordPress - Creating a Custom Post Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('init', 'register_cpt', 1); // Set priority to avoid plugin conflicts | |
function register_cpt() { | |
$singular = "_cpt_name_"; | |
$plural = "_cpt_name_plural_"; | |
$labels = array( | |
'name' => _x($plural, 'post type general name'), | |
'singular_name' => _x($singular, 'post type singular name'), | |
'add_new' => _x('Add New', $singular), | |
'add_new_item' => __('Add New '.$singular), | |
'edit_item' => __('Edit '.$singular), | |
'new_item' => __('New '.$singular), | |
'view_item' => __('View '.$singular), | |
'search_items' => __('Search '.$plural), | |
'not_found' => __('No '.$plural.' found'), | |
'not_found_in_trash' => __('No '.$plural.' found in Trash'), | |
'parent' => __( 'Parent' ), | |
'parent_item_colon' => __( 'Parent' ) | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'hierarchical' => true, | |
'menu_position' => 5, | |
'has_archive' => strtolower($plural), | |
'taxonomies' => array( 'category' ), | |
'supports' => array('author', 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'page-attributes') | |
); | |
register_post_type( strtolower($plural), $args ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment