Last active
July 26, 2016 16:19
-
-
Save derekshirk/f76e5aad15ce6e0797078440e2a2ea6d to your computer and use it in GitHub Desktop.
A Better Approach to Registering Custom Post Types for WordPress
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
<?php /* | |
/* ------------------------------------------------- */ | |
/* Use Variables to Make Registering CPTs Easier | |
/* ------------------------------------------------- */ | |
function register_my_cpt_name() { | |
$name = 'My Custom Post Type' ; | |
$singular = 'The Custom Post Types' ; | |
$plural = 'Custom Posts (Types)' ; | |
$labels = array( | |
'name' => __( $name ), | |
'singular_name' => __( $singular ), | |
'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' . $name ), | |
'not_found' => __( 'No' . $name .'Found' ), | |
'not_found_in_trash' => __( 'No' .$name. 'Found in Trash' ), | |
'parent_item_colon' => '' | |
); | |
$args = array( | |
'labels' => $labels, | |
'menu_icon' => 'dashicons-format-status', | |
'public' => false, | |
'publicly_queryable' => false, | |
'show_ui' => true, | |
'query_var' => true, | |
'capability_type' => 'manage_options', | |
'hierarchical' => true, | |
'has_archive' => true, | |
'show_in_menu' => false, | |
'exclude_from_search' => true, | |
'supports' => false, | |
'rewrite' => array( 'slug' => __( $name )), | |
); | |
// See ccli_cpt_testimonials | |
register_post_type(__( 'custom-post-type-name' ), $args); | |
} | |
add_action( 'init', 'register_my_cpt_name' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment