Add Custom Post Type in WordPress without plugin

There are numerous plugins can be found through search results against Custom Post Type in WordPress repository which will allow to create custom post type for a WordPress site. They are might be excellent, good or average but one disadvantage to use plugin is added lots of functions with jQuery library that causes heavy loading of sites. Many functions may not be necessary with your own or purchased theme. Some plugins causes extra loading time for a site.

custom-post-type

So if you have a bit technical knowledge you can overcome this problem through use custom code for your site. This is very light, simple and convenient ease of use. So follow few steps that will take less time to install & setup than a WordPress plugin.

Let’s say your custom post type name is ‘SERVICE’.

# First open your functions.php and copy & paste the below code at the bottom:

add_action ('init', 'post_type_service'); 
function post_type_service() { 
$labels = array( 
		'name' => _x('Service', 'post type general name'), 
		'singular_name' => _x('Service', 'post type singular name'), 
		'add_new' => _x('Add Service', 'Content'), 
		'add_new_item' => __('Add New Service'), 
		'edit_item' => __('Edit Service'), 
		'new_item' => __('New Content'), 
		'view_item' => __('View Service'), 
		'search_items' => __('Search Content'), 
		'not_found' => __('Nothing found'), 
		'parent_item_colon' => '', 
		'menu_name' => __('Services') 
); 

$args = array( 
		'labels' => $labels, 
		'public' => true, 
		'publicly_queryable' => true, 
		'show_ui' => true, 
		'show_in_menu' => true, 
		'query_var' => true, 
		'rewrite'=> true, 
		'capability_type' => 'post', 
		'has_archive' => false, 
		'hierarchical' => false, 
		'menu_position' => 25, 
		'show_in_nav_menus' => true, 
		'supports' => array( 'title', 'editor', 'thumbnail','comments') 
); 

	register_post_type('service', $args); }

 

If you paste above full code & refresh your Admin Dashboard you can see one custom post type named ‘Services’ added in left navigation. Now your turn to make changes according to your own custom post type.

So change the name ‘your-custom-post-type-name’ i/o ‘service’ in every places. But must remember the register_post_type(‘post-type’, $args) function where you can pass the post type name & this name will use to display in front as single page.

Once done, just copy duplicate your single.php file and rename it as single-{custom-post-type}.php that will allows you to display post information. That’s all. Any further information’s please make a comment below. We will respond in our shortest period.

Thank you.

This post has already been read 2679 times!

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.

More Posts

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.