Skip to Content
PHPCODE
How to create post type in wordpress
wordpress code / November 26, 2022

How to create post type in wordpress:

/* register Gallery post type*/ 
function wodpress_gallery_posttype() {
$labels = array(
'name' => _x( 'Gallery', 'wodpress' ),
'singular_name' => _x( 'Gallery', 'wodpress' ),
'add_new' => _x( 'Add New', 'wodpress' ),
'add_new_item' => __( 'Add New Gallery' ),
'edit_item' => __( 'Edit Gallery' ),
'new_item' => __( 'New Gallery' ),
'all_items' => __( 'All Gallery' ),
'view_item' => __( 'View Gallery' ),
'search_items' => __( 'Search Gallery' ),
'not_found' => __( 'No Book found' ),
'not_found_in_trash' => __( 'No Book found in the Trash' ),
'menu_name' => 'Gallery'
); 
register_post_type( 'Gallery',
array(
'labels' => $labels,
'public' => true,
'has_archive' => false,
'supports' => array( 'title','thumbnail','editor'),
'rewrite' => array('slug' => 'gallery'),
'show_in_rest' => true,
)
);
}
add_action( 'init', 'wodpress_gallery_posttype' );

 

PHPCODE © 2023