
Custom post type in wordpress
Creating a custom post type in WordPress allows you to define and manage new types of content beyond the default posts and pages. This is particularly useful when you want to organize, display, and manage specific types of content with unique attributes. Custom post types are powerful tools that help you structure your website according to your needs.
In your theme's functions.php, use the register_post_type() function to define your custom post type.
function custom_post_type_blogs() {
$labels = array(
'name' => 'Blogs',
'singular_name' => 'Blog',
'menu_name' => 'Blogs',
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'menu_position' => 5,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'revisions', 'custom-fields', 'post-formats'),
'taxonomies' => array('category', 'post_tag'),
'rewrite' => array('slug' => 'blogs'),
);
register_post_type('blogs', $args);
}
add_action('init', 'custom_post_type_blogs');
In this example, we're creating a custom post type called "Blogs" You can customize the labels, features, and other parameters to match your content type.
List of all supports parameter
The supports parameter in the register_post_type() function allows you to specify which features and functionality you want to enable for your custom post type. Options include 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields', 'author', 'trackbacks', 'comments', ''revisions', 'page-attributes', 'post-formats'. Choose the ones that fit your content type.
Set Up Taxonomies
You can associate taxonomies (like categories and tags) with your custom post type to enhance content organization. Use the taxonomies parameter in the register_post_type() function to include the desired taxonomies.
Set Up Rewrite Rules
The rewrite parameter lets you define the URL structure for your custom post type. Specify a 'slug' to determine the post type's URL.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Wordpress
- Function to get the post id in while (have_posts()) : the_post();
- How to use shop in product category and product permalink in woocommerce
- Remove every class and ID from the wp_nav_menu
- How to hide PHP Warnings and Notices in WordPress?
- Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2348617 bytes) in /home/xxx/public_html/wp-includes/plugin.php on line xxx
- Show template file name in wordpress
- How to display author avatar in Wordpress 5
- Remove class from body tag in wordpress
- Add new class to body tag in wordpress
- Create shortcode in wordpress functions php
- Replace Live Site Url with Local Site URL in wordpress database