When creating custom post types while running the Genesis Framework, you can add a support for the custom post types called genesis-cpt-archives-settings
. This support creates an “Archive Settings” sub-menu page for your custom post type where you can set things like a headline, intro text, layout, etc. For more information on this feature and instructions on how to use it, see Ryan Meier’s post on Custom post type settings in Genesis 2.0.
To illustrate how we can use these settings manually, I’ll be using the headline and intro-text settings for a custom post type called “Service”. By default, Genesis outputs the headline (h1 tag) and intro-text (p tag) in a div above the archive loop (the main content). This happens as long as there are posts, otherwise it does not show. Normally, this will work for a lot of instances but it won’t if you want finer control of the output. Take a look at the code below and I’ll explain it next. Also, here’s a screenshot of my demo archive settings in the admin:
First, on line 10, this code removes the action that automatically outputs the headline and intro-text. Since we’ll be adding this ourselves with, presumably, our custom markup, we don’t need it there twice.
Next, we add an action at the same time as the one we just removed (genesis_before_loop
) to put our output in the same location. We’re basically swapping out the default function for our own.
The function we run to output everything is pretty simple; it just echoes the data (headline and intro-text) we’re retrieving. The important part here is how that data is retrieved. Genesis stores archive settings for each custom post type in an array and saves that array to the wp_options table, which means that we can fetch it using the get_option()
function. The thing to take note of is how the option is named:
genesis-cpt-archives-settings-{post_type}
Since each custom post type can have these archive settings, the post type support feature (genesis-cpt-archives-settings) is appended with “-{post_type}”. In this example, I’m using genesis-cpt-archives-settings-service
because my custom post type is called “service”.
To wrap up, here’s a screenshot of my custom output for the headline and intro-text on the fronted that corresponds to my admin settings shown above:
That’s it! Have fun.
Dan says
This is great, exactly what I was looking for! The one small problem I do have is that the paragraph tags / line breaks are stripped out of the intro text. Is there any way to retain the formatting?
Any advice much appreciated.
Kevin says
This is great information, but I’m still having trouble getting to the point of enabling the CPT Archive Settings on the dashboard menu. I used the Types plugin to create my CPT. Any ideas how to enable the Archive Settings? Thanks in advance!
Ren says
Hi, Kevin. Add this line to a custom plugin or your theme’s functions.php:
Make sure to change post_type to your post type’s key.