Created
March 27, 2018 10:20
-
-
Save ApoGouv/902485383bfb2005625585220f21db30 to your computer and use it in GitHub Desktop.
WP - Custom Post Type - Example: 'Portfolio'
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
// Register Custom Post Type Portfolio | |
// Post Type Key: portfolio | |
function create_portfolio_cpt() { | |
$labels = array( | |
'name' => __( 'Portfolios', 'Post Type General Name', 'cube-cpt-portfolio' ), | |
'singular_name' => __( 'Portfolio', 'Post Type Singular Name', 'cube-cpt-portfolio' ), | |
'menu_name' => __( 'Portfolios', 'cube-cpt-portfolio' ), | |
'name_admin_bar' => __( 'Portfolio', 'cube-cpt-portfolio' ), | |
'archives' => __( 'Portfolio Archives', 'cube-cpt-portfolio' ), | |
'attributes' => __( 'Portfolio Attributes', 'cube-cpt-portfolio' ), | |
'parent_item_colon' => __( 'Parent Portfolio:', 'cube-cpt-portfolio' ), | |
'all_items' => __( 'All Portfolios', 'cube-cpt-portfolio' ), | |
'add_new_item' => __( 'Add New Portfolio', 'cube-cpt-portfolio' ), | |
'add_new' => __( 'Add New', 'cube-cpt-portfolio' ), | |
'new_item' => __( 'New Portfolio', 'cube-cpt-portfolio' ), | |
'edit_item' => __( 'Edit Portfolio', 'cube-cpt-portfolio' ), | |
'update_item' => __( 'Update Portfolio', 'cube-cpt-portfolio' ), | |
'view_item' => __( 'View Portfolio', 'cube-cpt-portfolio' ), | |
'view_items' => __( 'View Portfolios', 'cube-cpt-portfolio' ), | |
'search_items' => __( 'Search Portfolio', 'cube-cpt-portfolio' ), | |
'not_found' => __( 'Not found', 'cube-cpt-portfolio' ), | |
'not_found_in_trash' => __( 'Not found in Trash', 'cube-cpt-portfolio' ), | |
'featured_image' => __( 'Featured Image', 'cube-cpt-portfolio' ), | |
'set_featured_image' => __( 'Set featured image', 'cube-cpt-portfolio' ), | |
'remove_featured_image' => __( 'Remove featured image', 'cube-cpt-portfolio' ), | |
'use_featured_image' => __( 'Use as featured image', 'cube-cpt-portfolio' ), | |
'insert_into_item' => __( 'Insert into Portfolio', 'cube-cpt-portfolio' ), | |
'uploaded_to_this_item' => __( 'Uploaded to this Portfolio', 'cube-cpt-portfolio' ), | |
'items_list' => __( 'Portfolios list', 'cube-cpt-portfolio' ), | |
'items_list_navigation' => __( 'Portfolios list navigation', 'cube-cpt-portfolio' ), | |
'filter_items_list' => __( 'Filter Portfolios list', 'cube-cpt-portfolio' ), | |
); | |
$args = array( | |
'label' => __( 'Portfolio', 'cube-cpt-portfolio' ), | |
'description' => __( 'Create Portfolio Items', 'cube-cpt-portfolio' ), | |
'labels' => $labels, | |
'menu_icon' => 'dashicons-welcome-write-blog', | |
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'author', 'comments', 'trackbacks', 'page-attributes', 'post-formats', 'custom-fields', ), | |
'taxonomies' => array('Skills', 'Companies', ), | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_position' => 5, | |
'show_in_admin_bar' => true, | |
'show_in_nav_menus' => true, | |
'can_export' => true, | |
'has_archive' => true, | |
'hierarchical' => false, | |
'exclude_from_search' => false, | |
'show_in_rest' => true, | |
'publicly_queryable' => true, | |
'capability_type' => 'post', | |
); | |
register_post_type( 'portfolio', $args ); | |
} | |
add_action( 'init', 'create_portfolio_cpt', 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment