Create custom post type in wordpress


<?php
   
    // ******************************************************************************
    // *** REMEMBER TO PUT THIS CODE INSIDE 'functions.php' inside your themes folder.
    // ******************************************************************************
   
   
    add_action('init', 'postType_custom', 1);
    // '1' is to Set priority to avoid plugin conflicts.
    // 'postType_custom' can be any UNIQUE function name
   
    function postType_custom() { // A unique name for our function
        $labels = array( // Used in the WordPress admin
            'name' => _x('Custom_Post_Type', 'post type general name'),
            'singular_name' => _x('Custom_Post_Type', 'post type singular name'),
            'add_new' => _x('Add New', 'Custom_Post_Type'),
            'add_new_item' => __('Add New Custom_Post_Type'),
            'edit_item' => __('Edit Custom_Post_Type'),
            'new_item' => __('New Custom_Post_Type'),
            'view_item' => __('View Custom_Post_Type'),
            'search_items' => __('Search Custom_Post_Type'),
            'not_found' =>  __('Nothing found'),
            'not_found_in_trash' => __('Nothing found in Trash')
        );
        // 'Custom_Post_Type' replace this with the name of your post type
       
        $args = array(
            'labels' => $labels, // Set above
            'public' => true, // Make it publicly accessible
            'hierarchical' => false, // No parents and children here
            'menu_position' => 5, // Appear right below "Posts"
            'has_archive' => 'custom-post-type', // Activate the archive
            'supports' => array('title', 'editor', 'thumbnail', 'trackbacks', 'comments' ), // The options you want to see when you add the Custom_Post_Type
        );
        register_post_type( 'custom-post-type', $args ); // Create the post type, use options above
        // 'custom-post-type' will be the url of your Custom Post type. So choose wisely and replace.
    }
    // -- END Creating Custom post-type
?>

// ******************************************************************************
// *** REMEMBER TO PUT THIS CODE INSIDE ‘functions.php’ inside your themes folder.
// ******************************************************************************

Latest Comments

Leave a Reply

comment on this article