The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Register a Custom Post Type

Shared by Amit Dholiya · October 10, 2026 · @init

2 views
1 upvote
Back to Snippets

Creates a new content type, for example “Portfolio”.

 

How to use: Add it to functions.php (or better, a small plugin so it survives theme changes). Then go to Settings → Permalinks → Save to flush rewrite rules.

function my_register_portfolio() {
    register_post_type( 'portfolio', array(
        'labels'       => array(
            'name'          => 'Portfolio',
            'singular_name' => 'Project',
        ),
        'public'       => true,
        'has_archive'  => true,
        'menu_icon'    => 'dashicons-portfolio',
        'supports'     => array( 'title', 'editor', 'thumbnail' ),
        'show_in_rest' => true,
    ) );
}
add_action( 'init', 'my_register_portfolio' );

Tested on

WordPress 6.8

Reported by the author on October 10, 2026. WPFolks has not verified this.

Not tested against WordPress 7.1.3. It may still work.

Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments