How to create custom post type in wordpress

Topics focus on Web Developments, Programming, Database, Digital Marketing Tutorials, Code Snippets, SEO, Social Media Marketing and Inspirational articles.

How to create custom post type in wordpress

How to create custom post type in wordpress

How to create custom post type in wordpress

Hello Friends..!! I am writing this article about How to create custom post type in wordpress. Many times user want to create their own custom post type but they didn’t know how to do it. So here I wrote some codes for it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
add_action( 'init', 'register_cpt_news' );
function register_cpt_news() {
    $labels = array(
		'name' => _x( 'news', 'news' ),
		'singular_name' => _x( 'news', 'news' ),
		'add_new' => _x( 'Add New', 'news' ),
		'add_new_item' => _x( 'Add New news', 'news' ),
		'edit_item' => _x( 'Edit news', 'news' ),
		'new_item' => _x( 'New news', 'news' ),
		'view_item' => _x( 'View news', 'news' ),
		'search_items' => _x( 'Search news', 'news' ),
		'not_found' => _x( 'No news found', 'news' ),
		'not_found_in_trash' => _x( 'No news found in Trash', 'news' ),
		'parent_item_colon' => _x( 'Parent news:', 'news' ),
		'menu_name' => _x( 'news', 'news' ),
    );
    $args = array(
		'labels' => $labels,
		'hierarchical' => true,
		'description' => 'this will be showing news in the site',
		'supports' => array( 'title', 'editor', 'excerpt', 'revisions' ),
		'taxonomies' => array( 'category', 'national', 'international', 'local', 'sports', 'breaking' ),
		'public' => true,
		'show_ui' => true,
		'show_in_menu' => true,
		'menu_position' => 20,
		'show_in_nav_menus' => true,
		'publicly_queryable' => true,
		'exclude_from_search' => false,
		'has_archive' => true,
		'query_var' => true,
		'can_export' => true,
		'rewrite' => true,
		'capability_type' => 'page'
    );
    register_post_type( 'news', $args );
}

Add comment


 

Pin It on Pinterest

Share This