my code stock.com

Tobias Hopp

Register Custom Post Type ( functions.php / pluginname.php)
by Tobias Hopp

Register your custom post type in WordPress

Snippet options

Download: Download snippet as register-custom-post-type-functionsphp-pluginnamephp.php.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

/* Create Custom Post Type for the Cube */
if(!function_exists('the_cube_init')) {
    function the_cube_init() {

        register_post_type( 'cube',
            array(
                'labels' => array(
                'name' => __( 'The Cube', 'the-cube'),
                'singular_name' => __( 'The Cube', 'the-cube' )),
                'public' => true,
                'publicly_queryable' => true,
                'has_archive' => true,
                'menu_icon'   => 'dashicons-screenoptions',
                'query_var' => true,
                'excerpt' => true,
                'rewrite' => array('slug' => 'cube')
            )
        );

        function the_cube_rewrite_flush() {
            // First, we "add" the custom post type via the above written function.
            // Note: "add" is written with quotes, as CPTs don't get added to the DB,
            // They are only referenced in the post_type column with a post entry, 
            // when you add a post of this CPT.
            the_cube_init();

            // ATTENTION: This is *only* done during plugin activation hook in this example!
            // You should *NEVER EVER* do this on every page load!!
            // flush_rewrite_rules();
        }
        register_activation_hook( __FILE__, 'the_cube_rewrite_flush' );
    }
}
add_action( 'init', 'the_cube_init' );

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.