• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Genesis Snippets

A reference for Genesis theme developers

  • Home
  • Archives
  • Search Genesis Snippets

custom post type

Template plugin for custom post type with sidebar

June 19, 2018 By David Wang Leave a Comment

I often want to create a custom post type with an accompanying sidebar. For example, a Lessons sidebar that only displays on Lessons and Programs (a related taxonomy). Here is a simple plugin that does just that, or provides a basis for customization. You can also copy the code into your functions.php file directly.

View plugin code, or download plugin.

A couple of points to note:

The plugin some Genesis features to the Lessons post type. Comment out the features you don’t need, or simply delete this block:

add_action( 'genesis_init', 'child_lessons_theme_supports' );
/*
 * Add theme supports to Lessons
 */
function child_lessons_theme_supports() {
	add_post_type_support( 'lesson', array(
		'genesis-cpt-archives-settings',  // Archive settings
		'genesis-layouts',    // In-post layout settings
		'genesis-seo',        // In-post SEO settings
		'genesis-scripts',    // In-post script options
	) );
}

The plugin also removes the post meta and post info by default. If you want these, delete this block of code:

add_action( 'genesis_before', 'child_remove_lesson_meta', 11 );
/*
 * Remove post info and meta for Lessons
 */
function child_remove_lesson_meta() {
	// Remove post info
	remove_post_type_support( 'lesson', 'genesis-entry-meta-before-content' );
	// Remove post meta
	remove_post_type_support( 'lesson', 'genesis-entry-meta-after-content' );
}

Hope you find it useful 🙂

Filed Under: Genesis Tagged With: custom post type, widget areas

Enable Genesis Layout and SEO settings for custom post types

October 29, 2015 By David Wang Leave a Comment

If you have a custom post type and want to enable the Genesis Layout and SEO settings on the Add New / Edit screens for it, use this snippet:

 
add_post_type_support( 'post_type_id', // e.g. product or portfolio 
	array( 
		'genesis-layouts', 
		'genesis-seo' 
	) 
); 

Or, you can also declare support for these features when registering a custom post type (hat tip to Chuck Smith in the comments).

 
add_action( 'init', 'codex_book_init' );
/**
* Register a book post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
function codex_book_init() {

	$labels = array(
	...
	);
	
	$args = array(
	'labels' => $labels,
	'description' => __( 'Description.', 'your-plugin-textdomain' ),
	'supports' => array( 
		'title', 
		'editor', 
		'comments', 
		'genesis-seo',
		'genesis-layouts',
		'genesis-simple-sidebars',
		'genesis-cpt-archives-settings' 
		),
	);
	register_post_type( 'book', $args );

}

See also: Understanding and using Genesis Layout Settings

Filed Under: Genesis Tagged With: custom post type

Display a custom sidebar on a custom post type

December 28, 2012 By David Wang

Here’s how to replace the primary sidebar on a custom post type. First, register your sidebar. Next, use this code to swap the primary sidebar with the new one you just registered:

// Swap sidebars on CPT pages
add_action('get_header','child_change_genesis_sidebar');
function child_change_genesis_sidebar() {
	if ( is_singular('post_type')) { // change 'post_type' to your CPT slug
		remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); //remove the default genesis sidebar
		add_action( 'genesis_sidebar', 'child_do_cpt_sidebar' ); //add an action hook to call the function for my custom sidebar
	}
}
 
// Output sidebar with the id 'sidebar-custom'
function child_do_cpt_sidebar() {
	genesis_widget_area( 'sidebar-custom' );
}

If you want to display the sidebar on both the single post page and archive page for your custom post type, modify the if statement in child_change_genesis_sidebar() function to include

if ( is_singular('post_type') || is_post_type_archive('post_type') ) {

Credit: Carrie Dils & Travis Smith from How to Use a Custom Sidebar on a Custom Post Type

Filed Under: Genesis Tagged With: custom post type, sidebars, widget areas

Remove Genesis layout settings for a Custom Post Type

July 29, 2012 By David Wang

If you’ve forced a layout for a custom post type, there’s no need to display the Layout Settings metabox in the edit screen. Here’s a code snippet that removes the layout options for a product custom post type.

/** Remove Genesis inpost layouts from 'product' post_type */
add_action( 'init', 'child_remove_post_type_support' );
function child_remove_post_type_support() {
	remove_post_type_support( 'product', 'genesis-layouts' );
}

Replace product with the custom post type you want this to work for.

Credit: Ade Walker, gleaned from his article How to use Genesis Connect for WooCommerce.

Want to remove the default layout metabox in the Genesis Theme Settings page instead? Use this snippet: Remove unused theme settings metaboxes

Filed Under: Genesis Tagged With: custom post type, metabox, page layouts, theme options

Primary Sidebar

Brought to you by ClickWP
Buy the Genesis Theme Framework

Who’s behind this?

Hi! I'm David and I'm a big Genesis fan. I've been using it in all my projects and have found it to be super powerful.

I started this site to keep track of all the snippets that I've been using in my projects and so that it's easy for me to find them again instead of digging through my old project files.

Help support this site by buying Genesis with our affiliate links. Thanks!

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 354 other subscribers

Browse Snippets

branding cache comments css custom post type doctype entry footer entry header favicon featured image genesis_custom_loop images internet explorer jetpack loop media menu metabox minify navigation oembed page layouts performance plugin integration post thumbnail shortcode sidebars theme options widget areas widgets WooCommerce WordPress
Everything you need to support your online business
Take WordPress further with the Genesis framework

Copyright © 2025 · Genesis Sample On Genesis Framework · WordPress · Log in