If you’re a WordPress developer, or even just a tinkerer, you know that code can be a great way to add new features to your site…
By: Date: April 22, 2023 Categories: Wordpress Tags:

If you’re a WordPress developer, or even just a tinkerer, you know that code can be a great way to add new features to your site. And while there are tons of plugins out there that can do just about anything, sometimes it’s nice to be able to add a small piece of code to your site to add a new feature.

In this post, we’ll share some code that can be used to create a WordPress plugin. This code will allow you to create a custom post type for your site.

Creating a custom post type is a great way to add new content to your site. For example, if you have a blog about travel, you could create a custom post type for “travel stories.” This would allow you to add new content to your site without having to create a new post for each story.

The code below will allow you to create a custom post type for your WordPress site. To use this code, simply copy and paste it into your functions.php file.

function create_custom_post_type() {

// Set up labels
$labels = array(
‘name’ => ‘Travel Stories’,
‘singular_name’ => ‘Travel Story’,
‘add_new’ => ‘Add New’,
‘add_new_item’ => ‘Add New Travel Story’,
‘edit_item’ => ‘Edit Travel Story’,
‘new_item’ => ‘New Travel Story’,
‘all_items’ => ‘All Travel Stories’,
‘view_item’ => ‘View Travel Story’,
‘search_items’ => ‘Search Travel Stories’,
‘not_found’ => ‘No Travel Stories Found’,
‘not_found_in_trash’ => ‘No Travel Stories found in Trash’,
‘parent_item_colon’ => ”,
‘menu_name’ => ‘Travel Stories’,
);

// Register post type
register_post_type( ‘travel_story’, array(
‘labels’ => $labels,
‘public’ => true,
‘supports’ => array( ‘title’, ‘editor’, ‘excerpt’, ‘author’, ‘thumbnail’, ‘comments’, ‘revisions’, ‘custom-fields’, ),
‘capability_type’ => ‘post’,
‘taxonomies’ => array( ‘category’ ),
‘hierarchical’ => false,
‘rewrite’ => array( ‘slug’ => ‘travel-stories’ ),
‘has_archive’ => true
)
);
}
add_action( ‘init’, ‘create_custom_post_type’ );

?>
This code will create a custom post type for your WordPress site. This is a great way to add new content to your site without having to create a new post for each story. Simply copy and paste this code into your functions.php file and you’ll be up and running in no time!

Leave a Reply

Your email address will not be published. Required fields are marked *