This page may contain affiliate links. Please read my disclaimer for more information.

How to create a WordPress custom post type for a Genesis child theme

For a resent project, restaurant theme design, I needed to create two Custom Post Types. One to manage the post that would be used in the homepage slider and the second to manage the recipes.

This wasn’t necessary, especially with the Genesis Framework we use for developing websites, there is a plugin called Genesis Responsive Slider that will allow you to display content from the Post or Page section of your WordPress website and even identify a specific category of posts to be displayed in the slider.

However, I did not want to confuse my client, and clutter the Post section with the content being used in the slider.

What the dashboard looks like with the added post types

Restaurant Website Design

Let’s Get Started

First thing we need to do is find and open the function.php file, which is located within your theme folder.

Next step is to copy and past this code into your themes function.php file.

 
/** Register slider custom post type */
add_action( 'init', 'slider_post_type' );
function slider_post_type() {
    register_post_type( 'slider',
        array(
            'labels' => array(
                'name' => __( 'Slider' ),
                'singular_name' => __( 'Slider Images' ),
            ),
            'has_archive' => false,
            'public' => true,
            'rewrite' => array( 'slug' => 'slider' ),
            'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'genesis-seo', 'comments' ),
        )
    );
}
 

Once you have added this code to your functions.php file and saved your changes, you will want to go directly to Permalinks and click the save button. Settings => Permalinks => Click Save Changes. This will help register the rewrites that are being made.

Code Explanation

First thing, anywhere in the code where you see “Slider” you can change to the name of your custom post type.

The ‘labels’, name and singular_name, this is what is used to display the name of your post type in the dashboard.

The ‘has_archive’ section will, if set to true, enable post type archives. Giving you a the ability to have an archive page for the items in your new post type. For this situation this is set to false because it was not necessary.

The ‘public’ section when sent to “true”, which will usually be the case, allows you to use the post type in the dashboard and allows the items in the post type to be visible from the front-end.

The ‘rewrite’ section handles all the rewrites required for this post type. In this case the ‘slug’ is being rewritten to slider. The url for anything added to the slider post type is going to be changed to, https://domainname.com/slider/post-name.

The ‘supports’ section is very important. This is the section that determines the available features within the post type editor. In this case we are registering only the items we will need.

It is really that simple.

For more on each of these code sections, visit the Custom Post Type Codex on WordPress.org

If you need some additional help getting your Custom Post Type setup, use the comments or contact me and I’ll do what we can!

Leave a Comment

Join The Mantis Report

Get weekly WordPress news, resources, tutorials, and other tips from our experts.

Name*
This field is for validation purposes and should be left unchanged.

Skip to content