Search

Add Support for Layout Options and SEO Settings for CPT in Genesis

    Ankita Raikundalia
Listen to this article
Support for Layout Options, Archive and SEO Settings for CPT
Support for Layout Options, Archive and SEO Settings for CPT

It’s easy- building a site on the Genesis Framework. You buy the framework, select a child theme, and… *ta-da*.. done! Ummm… not really. Doesn’t work that way. Not in the real world at least. Not to take anything away from the Genesis framework (it does save me a lot of time, when building a theme from scratch). But! In the real world, clients have requirements that change quite often. And minor changes can take up a lot of development time.

So this is what I do. I make things easy for me, by keeping minor changes simple for the client. (Another reason why I prefer the Genesis Framework). See, the Genesis framework provides several options using which clients can make simple changes themselves.

[space]

Layout Options in Genesis

In Genesis, the ‘Layout Option’ available on the admin settings page of every post or page, can be used to change layout of the particular post or page.

Genesis Layouts

These layout options provided, satisfy a majority of the use cases, or requirements a client has. And since the interface provided to change the layout option is quite easy to understand, most clients can make the needed changes themselves.

Add Layout Option Support for Custom Post Types

However, for Custom Post Types, this option is not available. And this can be a problem, because, most client websites usually have a custom post type. So, to save them the effort, of having to contact me to change the layout of a custom post type page template, I always add support for ‘Layout Options’, for CPTs in Genesis. Here’s how!

When creating a custom post type in Genesis, you need to add support for ‘genesis-layouts’. In the args parameter, of the ‘register_post_type’ function, there is a field ‘supports’. Just append ‘genesis-layouts’, to the supports array. Take a look at the example code below: 

add_action( 'init', 'wdm_create_custom_post_type' );
function wdm_create_custom_post_type() {
  // set-up parameters
  
  $args = array(
    /* other fields here */
    'supports'  => array( 'title', 'editor',  'thumbnail', 'post­-formats', 'comments', 'excerpt', 'genesis-­layouts')
  );
  register_post_type( 'your_cpt', $args );
}

[space]

SEO Settings for Custom Post Types in Genesis

Similarly, another key feature of the Genesis framework is built-in SEO meta fields. Using these fields clients can easily add values to quickly optimize their website for search engines. Again the problem here is that SEO support is not available for custom post types, (as explained in one of our previous posts on Genesis SEO vs WordPress SEO), and this is one of the major reasons why users prefer using a different plugin.

However, for those clients who do not want to opt for a different plugin, there is a solution. You can add support for SEO settings, ‘genesis-seo’, as well for Custom Post Types.

'supports'  => array( 'title', 'editor',  'thumbnail', 'post­-formats', 'comments', 'excerpt', 'genesis-­layouts', 'genesis-seo')

A client can then use these meta fields to add SEO parameters for custom post types.

[space]

Archive Settings Support for Custom Post Types in Genesis

The archive page, is basically a page which contains a collection of all posts, belonging to a particular post type. For example, the blog, is an archive page of all posts. Since an archive page can be useful when it comes to navigating across your site, they are needed even for custom post types. And as you guessed it, Genesis by default does not provide support for archive settings for custom post types. We need to thus explicitly add support for archive settings. For this, we need to add the following in the ‘args’ parameter:

'has_archive' => true,
'public' => true,
'supports'  => array( 'title', 'editor',  'thumbnail', 'post­-formats', 'comments', 'excerpt', 'genesis-­layouts', 'genesis-seo', 'genesis­-cpt­-archives­-settings')

Once the archive page is ready, the client can directly add it to a menu option if needed.

Note:

Now, all this code will work fine when you are creating the custom post type yourself, for the client. But what when the client wants the possibility to create a CPT himself, say by using a plugin like Custom Post Type UI? Well, in that case, you need find a hook provided by CPT UI, and set the default options for the args fields with the values specified above.

[space]

There isn’t a theme framework out there, that satisfies all client requirements out-of-the-box. But Genesis does help make the process simpler, because it provides in-built hooks and filters, to incorporate any changes as per client requirements. So if you were looking to make similar changes in your Genesis theme, use the above code, and you should be good. Do let me know if you have any additional questions, or have suggestions for fellow readers, using the comment section below.

 

Ankita Raikundalia

Ankita Raikundalia

Leave a Reply

Your email address will not be published. Required fields are marked *

Get The Latest Updates

Subscribe to our Newsletter

A key to unlock the world of open-source. We promise not to spam your inbox.

Suggested Reads

Join our 55,000+ Subscribers

    The Wisdm Digest delivers all the latest news, and resources from the world of open-source businesses to your inbox.

    Suggested Reads