Custom post type archive settings in Genesis 2.0

Custom post type archive settings in Genesis 2.0

Ever since I started using Genesis, I have spent a lot of time studying the source code.  The other day I noticed a new class that was included in 2.0 beta; Custom Post Type Archive Settings.

So… What is it?

Custom post type archive settings is a sub menu under a custom post type menu.

Archive Settings Submenu
Custom Post Type Archive Settings submenu

Within this menu, users will be able to specify an archive headline, intro text, SEO, and layout settings for the front-end custom post type archive page.

Custom Post Type Archive Settings Page
Custom Post Type Archive Settings Page

This will display a custom title and description on your custom post type archive page.  As an example, I have added a title and description to my projects archive page.

Custom Post Type Archive page title and description
Custom Post Type Archive page title and description

Enable archive settings support

This feature will probably work with most custom post types out-of-the-box.  While registering the custom post type, add ‘genesis-cpt-archives-settings’ to the support parameter within the register_post_type() arguments.  By adding this feature, Genesis will know to add the Archive Settings sub menu to your post type.

How this works with your custom post type

Before the admin menus are built, Genesis will grab post type objects that meet certain arguments.  Once the post type objects have been gathered, Genesis will check if the post type object supports the ‘genesis-cpt-archives-settings’ feature. Those remaining post type objects with ‘genesis-cpt-archives-settings’ support will have the archive settings menu.

I included the Genesis source code snippet above to demonstrate how post type objects are collected before creating the sub menus.  The code gathers post types with public, show_ui, show_in_menu, has_archive arguments set to true and _builtin set to false.  These arguments are defined when you register your post type.

These settings basically set the post type to be viewed on the front-end with the custom post type archive page and have admin menus generated by WordPress.  If the custom post type does not match these arguments, the ‘genesis_cpt_archives_args’ filter can be used to extend the functionality.

What if a plugin is registering a custom post type?  Support can be added after the custom post type has been registered with add_post_type_support().

Extendability

The custom post type archive class inherits from the Genesis_Admin_Boxes class.  This will allow developers to add additional meta boxes to their post type archive settings menu.

Published by

rfmeier

Product developer at WPEngine and runner from Hampshire, Illinois. I work with php a lot; Spending most of my time digging into source code to see how it all works. You can find me on Twitter @rfmeier.

15 thoughts on “Custom post type archive settings in Genesis 2.0”

  1. Good write-up Ryan.

    Additionally, if you register your CPT so that it DOESN’T have a top-level menu, the archive settings menu item *should* slip in right below it (more of an edge case that is hopefully still addressed).

  2. Hi Ryan

    Thanks to make this article about this new great genesis feature.
    Everything works well (archive setting and intro display) except I can use genesis hook in my new archive-$post_type.php file.

    WordPress apply this template for my CPT archive. I can make some php actions but the genesis hook do not works if I write it down in this file: archive-$post_type.php
    Have you an idea?

    Thanks
    Grégoire

    1. Grégoire,

      If you are sure the custom archive template is being used, then make sure you are not adding actions and filters too late within that file. Is this on Genesis 2.0?

      My Projects archive page uses a custom template with actions and filters. I haven’t had any problems getting the hooks to work correctly.

  3. Thanks! The information about ‘What if a plugin is registering a custom post type?’ at the end of your post helped to to add the line of code to my functions.php so that Custom Post Types I made with WP-Types show the Archive setting!

    Would you also happen to know how I can assign a specific sidebar to a custom post type archive page in Genesis?

  4. Thanks for the quick reply!

    I’ve added your code, I just remembered I added some similar to your code before and the result is the same. It does add a new widgetarea with one or more widget, but it does not delete the current sidebar. So visually it just adds a new widget on top of the existing sidebar on the archive page.

  5. This has been helpful, but I’m still having trouble getting the CPT Archive Settings to appear in the menu.

    I created the CTP using the Types plugin. Where do I enter the code to “add_post_type_support()”?

    I’m using a a child theme on the Genesis framework.

    Thanks again!

    1. Kevin,

      The add_post_type_support() should just be added to your child theme’s functions.php file.

      As for the menu, you will just need to add a the url as a custom link.

  6. Ryan,
    I wonder if there is or should be a more elegant way than adding a CPTs archive as custom link to the menu.
    Somehow, class=”menu-item menu-item-type-custom menu-item-object-custom menu-item-197″ does not seem to be quite up to the metadata standard set by Genesis is general; also I really don’t like that the CPT menu is not highlighted as “parent” in any way when a user opens a single post of this CPT.
    I found ways using the “Current Menu Item for Custom Post Types” plugin that uses a page to display the CPT archive (and keep the visual menu hierarchy), but this feels somewhat weird and hard to explain to clients.
    Thanks,
    Phil

    1. Philippe,

      I agree about adding the CPT archive as a link. It is more complicated than it should be, but a lot of the blame lands on how menu links are created by WordPress. I have been able to integrate the CPT archive page as a link in the menu, but it required way way way too much work.

  7. Ryan, thanks, this was helpful in getting started on adding a custom metabox to my archive settings page. It helped me figure out where to go in the core files to find the right hooks. 🙂 I saw you mentioned it as a possibility at the end of your post. Have you done it yourself? If so, an advice on getting the data to save properly?

    1. Amber,

      For adding custom meta boxes, you need at least three hooks;

      1. ‘genesis_cpt_archives_settings_metaboxes’ to add the meta boxes.
      2. ‘genesis_cpt_archive_settings_defaults’ to define a default setting value(s).
      3. ‘genesis_settings_sanitizer_init’ to sanitize the field before they are saved.

      This is a little hard to explain in a comment. If you want, you can contact me at ryan@rfmeier.net.

Leave a Reply

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