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.

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 2680 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.

Share
Published by
Mehedi Hasan

Recent Posts

WP Share A Friend – A Way to Capture Lead

What is Lead Capture: In general sense lead capture designates a process or way of…

5 years ago

Unlimited Modal POPUPS on MouseClick

Introduction Unlimited Modal POPUPS on MouseClick: Everyone knows about popup during site visits and most…

5 years ago

WordPress Pregnancy Calculator Plugin

Brief about Pregnancy Calculator : This WordPress Pregnancy Calculator plugin allows users to display an…

5 years ago

Interactive Service Plugin with Hover Effects VC

Introduction About this Service Plugin: This Visual Composer Service Plugin works as an addon to…

6 years ago

WP Dynamic Query String

Introduction of Dynamic Query String : This plugin allows user to set dynamic query string…

6 years ago

How to make scroll PDF in iFrame for iPAD Safari

There is an occasional bug for iPhone and iPad even they are designed as well and…

7 years ago