DEV Community

Samcorp
Samcorp

Posted on

How to Create a Custom Post Type in WordPress?

Problem
I want to create a custom post type in WordPress to manage additional content types like portfolios, testimonials, etc.

Solution
Add the following code to your theme's functions.php file:

function create_custom_post_type() {
    register_post_type('portfolio',
        array(
            'labels' => array(
                'name' => __('Portfolios'),
                'singular_name' => __('Portfolio')
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'portfolio'),
            'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'custom-fields'),
        )
    );
}
add_action('init', 'create_custom_post_type');
Enter fullscreen mode Exit fullscreen mode

WordPress development services to build custom websites that are fast, secure, and easy to manage. From creating themes and plugins to optimizing performance, we ensure your website meets your business needs. Get a professional, user-friendly site that stands out.

Top comments (0)