Do you want better
IT Services ?

Let our experts help you navigate the digital world with tailor-made IT Solutions!

Table of Contents

Adding a custom post type in wordpress is an easy task. You can learn a lot at at WordPress Codex about Post types.WordPress can hold and display many different types of content. A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored in the same place, in the wp_posts database table, but are differentiated by a column called post_type.

Minimum Code required to create a custom post type is following. This basic code has been taken from wordpress codex and this code will create a “Product” custom post type with minimum options. However below the basic code we have added advanced snippet with more arguments.


add_action( 'init', 'create_post_type' );
function create_post_type() {
	register_post_type( 'acme_product',
		array(
			'labels' => array(
				'name' => __( 'Products' ),
				'singular_name' => __( 'Product' )
			),
		'public' => true,
		'has_archive' => true,
		)
	);
}

Advanced Snippet to add Custom Post types in WordPress. One just need to add the following code in functions.php file to make a Portfolio custom post type. If you want a custom post type other then Portfolio, you can just replace word Portfolio with your Post Type name such as Event or Product. If you want to add more then one custom post type don’t forget to change function name everytime you create a custom post type. Make sure you write this code before php closing tag in functions.php

[box style=”green”]If you face a blank screen after adding this code,  and you can no longer access wordpress, you have played wrong with php syntax. That means you have opened <?php tag again before closing previous one. [/box]

 

If you face any problem while using this code, just write in a comment below.


if ( ! function_exists('portfolio_custom_post_type') ) {

// Register Custom Post Type
function portfolio_custom_post_type() {

$labels = array(
	'name'                => _x( 'Portfolios', 'Post Type General Name', 'text_domain' ),
	'singular_name'       => _x( 'Portfolio', 'Post Type Singular Name', 'text_domain' ),
	'menu_name'           => __( 'Portfolio', 'text_domain' ),
	'parent_item_colon'   => __( 'Parent Item:', 'text_domain' ),
	'all_items'           => __( 'All Items', 'text_domain' ),
	'view_item'           => __( 'View Item', 'text_domain' ),
	'add_new_item'        => __( 'Add New Item', 'text_domain' ),
	'add_new'             => __( 'Add New', 'text_domain' ),
	'edit_item'           => __( 'Edit Item', 'text_domain' ),
	'update_item'         => __( 'Update Item', 'text_domain' ),
	'search_items'        => __( 'Search Item', 'text_domain' ),
	'not_found'           => __( 'Not found', 'text_domain' ),
	'not_found_in_trash'  => __( 'Not found in Trash', 'text_domain' ),
	);
	$args = array(
	'label'               => __( 'portfolio', 'text_domain' ),
	'description'         => __( 'Post Type Description', 'text_domain' ),
	'labels'              => $labels,
	'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', 'post-formats', ),
	'taxonomies'          => array( 'category', 'post_tag' ),
	'hierarchical'        => false,
	'public'              => true,
	'show_ui'             => true,
	'show_in_menu'        => true,
	'show_in_nav_menus'   => true,
	'show_in_admin_bar'   => true,
	'menu_position'       => 5,
	'can_export'          => true,
	'has_archive'         => true,
	'exclude_from_search' => false,
	'publicly_queryable'  => true,
	'capability_type'     => 'page',
	);
	register_post_type( 'portfolio', $args );

}

// Hook into the 'init' action
add_action( 'init', 'portfolio_custom_post_type', 0 );

}

===========================================================

Adding Custom Post type using snippet file

  1. Click below button to download Custom Post type Snippet.
  2. Extract the zip file and add php file into your theme root folder
  3. Open functions.php and add the following code after php opening tag.

Following snippet file method for adding custom post types to your wordpress theme avoid’s any kind of silly coding errors.

require_once ('custom-post-type.php');

[button color=”#333333″ link=https://thinkncode.com/wp-content/uploads/2014/07/custom-post-type.zip target=”_self”]Download [/button]

 

WordPress vs A Custom based php Website

WordPress and a custom PHP website are two different approaches to building a website. Here are some differences between the two: Ease of use: WordPress is generally easier to use than a custom PHP website, because it has a user-friendly interface and a large number of plugins and themes that allow you to easily add...

Read More

10 ways to bring targeted audience to your website

Search engine optimization (SEO): Optimizing your website for search engines can help bring targeted traffic from people searching for keywords related to your business. Pay-per-click (PPC) advertising: PPC advertising platforms like Google AdWords allow you to create ads that appear at the top of search engine results pages when people search for specific keywords. Content...

Read More

Top 8 Benefits of Having a Website

Top 8 Benefits of Having a Website Whether you’re a small business or a large corporation, having a website is essential to your success. In today’s digital world, people are used to getting their information online, and if you don’t have a website, you’re missing out on a huge opportunity. A website allows you to...

Read More

What is web hosting and why do I need it ?

Unless you are planning to build a website from scratch, you will need web hosting. Web hosting is a service that provides you with the technology and resources necessary to build and maintain a website. Think of it this way: if a website is like a house, then web hosting is like the land it’s...

Read More

How To Find The Right Website Designer For Your Business

A website is the face of your business – so it’s important that you take the time to find a designer who will create something that accurately represents your company. In this blog post, we’ll explore the process of selecting a designer, what you should keep in mind when hiring one, and how to go...

Read More

A Guide To Why You Need A Dynamic Website

The world has changed. The way people search for things have changed. The way they use technology to do their work have changed. Gone are the days when you create a website and take it as it is, customers will want more information, they’ll want better content, so you need to be ready to provide...

Read More
Scroll to Top
Scroll to Top

We help businesses with Websites, Mobile Applications, Digital Marketing, E Commerce Solutions & Custom Software.