Ticker

6/recent/ticker-posts

Ad Code

Responsive Advertisement

How we have created new section called “Guides” without any Custom Post Type plugin?

How we have created new section called Guides without Custom Post Type plugin?

We are working on Creating new dedicated section called Guides on Crunchify which provides list of all Productivity tips and tricks.

We thought of creating new Custom Post Type (CPT) using a plugin but end up created it without any plugin.

Here a code snippet which I’ve put in to WordPress theme’s functions.php file.

Custom Post Type called “Guides” Code:

// Custom Post Type - Guides - START
function crunchify_guides_custom_post_type() {

        /**
         * Crunchify's Post Type: Guides.
         */

        $labels = [
                "name" => __( "Quick Guides", "crunchify-guides-custom-post-type" ),
                "singular_name" => __( "Guide", "crunchify-guides-custom-post-type" ),
                "menu_name" => __( "Guides", "crunchify-guides-custom-post-type" ),
                "all_items" => __( "All Guides", "crunchify-guides-custom-post-type" ),
                "add_new" => __( "Add new", "crunchify-guides-custom-post-type" ),
                "add_new_item" => __( "Add new Guide", "crunchify-guides-custom-post-type" ),
                "edit_item" => __( "Edit Guide", "crunchify-guides-custom-post-type" ),
                "new_item" => __( "New Guide", "crunchify-guides-custom-post-type" ),
                "view_item" => __( "View Guide", "crunchify-guides-custom-post-type" ),
                "view_items" => __( "View Guides", "crunchify-guides-custom-post-type" ),
                "search_items" => __( "Search Guides", "crunchify-guides-custom-post-type" ),
                "not_found" => __( "No Guides found", "crunchify-guides-custom-post-type" ),
                "not_found_in_trash" => __( "No Guides found in trash", "crunchify-guides-custom-post-type" ),
                "parent" => __( "Parent Guide:", "crunchify-guides-custom-post-type" ),
                "featured_image" => __( "Featured image for this Guide", "crunchify-guides-custom-post-type" ),
                "set_featured_image" => __( "Set featured image for this Guide", "crunchify-guides-custom-post-type" ),
                "remove_featured_image" => __( "Remove featured image for this Guide", "crunchify-guides-custom-post-type" ),
                "use_featured_image" => __( "Use as featured image for this Guide", "crunchify-guides-custom-post-type" ),
                "archives" => __( "Guide archives", "crunchify-guides-custom-post-type" ),
                "insert_into_item" => __( "Insert into Guide", "crunchify-guides-custom-post-type" ),
                "uploaded_to_this_item" => __( "Upload to this Guide", "crunchify-guides-custom-post-type" ),
                "filter_items_list" => __( "Filter Guides list", "crunchify-guides-custom-post-type" ),
                "items_list_navigation" => __( "Guides list navigation", "crunchify-guides-custom-post-type" ),
                "items_list" => __( "Guides list", "crunchify-guides-custom-post-type" ),
                "attributes" => __( "Guides attributes", "crunchify-guides-custom-post-type" ),
                "name_admin_bar" => __( "Guide", "crunchify-guides-custom-post-type" ),
                "item_published" => __( "Guide published", "crunchify-guides-custom-post-type" ),
                "item_published_privately" => __( "Guide published privately.", "crunchify-guides-custom-post-type" ),
                "item_reverted_to_draft" => __( "Guide reverted to draft.", "crunchify-guides-custom-post-type" ),
                "item_scheduled" => __( "Guide scheduled", "crunchify-guides-custom-post-type" ),
                "item_updated" => __( "Guide updated.", "crunchify-guides-custom-post-type" ),
                "parent_item_colon" => __( "Parent Guide:", "crunchify-guides-custom-post-type" ),
        ];

        $args = [
                "label" => __( "Guides", "crunchify-guides-custom-post-type" ),
                "labels" => $labels,
                "description" => "",
                "public" => true,
                "publicly_queryable" => true,
                "show_ui" => true,
                "show_in_rest" => true,
                "rest_base" => "",
                "rest_controller_class" => "WP_REST_Posts_Controller",
                "has_archive" => true,
                "show_in_menu" => true,
                "show_in_nav_menus" => true,
                "delete_with_user" => false,
                "exclude_from_search" => false,
                "capability_type" => "post",
                "map_meta_cap" => true,
                "hierarchical" => true,
                "rewrite" => [ "slug" => "guides", "with_front" => true ],
                "query_var" => true,
                "menu_icon" => "dashicons-admin-customizer",
                "supports" => [ "title", "editor", "thumbnail", "excerpt", "trackbacks", "custom-fields", "comments", "revisions", "author", "page-attributes", "post-formats" ],
                "taxonomies" => [ "category", "post_tag" ],
                "yarpp_support" => true,
                "show_in_graphql" => true,
        ];

        register_post_type( "guides", $args );
}

add_action( 'init', 'crunchify_guides_custom_post_type' );

// Custom Post Type - Guides - END

And that’s it.

Just save your functions.php file and you will see new section Guides appears in your WordPress Admin Panel’s sidebar.

Custom Type Type Guides appears in WordPress Sidebar

Check it out here live examples:

We choose to use default taxonomies

"taxonomies" => [ "category", "post_tag" ]

As you see above, we choose to use default taxonomies as we don’t have any need to choose new one.

That means, WordPress Post Editor shows default Categories and Tags options.

WordPress Post Editor shows default Categories and Tags options

New section will appear in Menu option too.

  • Click on Appearance
  • Click on Menus
  • You will see new section there too called Quick Guides
Custom Post Type Guides appearing in Menu bar

Let me know if you face any issue creating new Custom Post Type.

The post How we have created new section called “Guides” without any Custom Post Type plugin? appeared first on Crunchify.

Enregistrer un commentaire

0 Commentaires