• 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

David Wang

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

Remove default widgets from Genesis, WordPress and WooCommerce

January 6, 2018 By David Wang Leave a Comment

Christina Arasmo Beymer posted a super code snippet in the Genesis Facebook Group. The following will remove default widgets from WordPress, Genesis and WooCommerce.

Filed Under: Genesis Tagged With: widgets, WooCommerce, WordPress

Serve minified stylesheet when SCRIPT_DEBUG or WP_DEBUG is defined

February 18, 2017 By David Wang Leave a Comment

If you use a workflow automation tool or task runner (e.g. Gulp or Grunt) you may be minifying your stylesheet. The following code snippet allows you to serve the minified stylesheet by default, but load the un-minified version for debugging complete with a cache-busting query parameter when debugging.

[Read more…] about Serve minified stylesheet when SCRIPT_DEBUG or WP_DEBUG is defined

Filed Under: Genesis Tagged With: cache, css, minify, performance

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

Add permalink to [post_date] shortcode

July 9, 2014 By David Wang

Here’s a snippet to make the post date into a link. This snippet only outputs a HTML5 post date, if you need an XHTML version just edit the $new_output variable.

add_filter( 'genesis_post_meta', 'child_post_meta_filter' );
function child_post_meta_filter($post_meta) {
	if ( !is_page() ) {
		$post_meta = '[post_categories before=""] [post_date]';
	}
	return $post_meta;
}

//* Add permalink to [post_date] shortcode
add_filter( 'genesis_post_date_shortcode', 'child_customize_post_date_shortcode', 10, 2 );
function child_customize_post_date_shortcode( $output, $atts ) {

	global $post;
	$defaults = array(
		'after'  => '',
		'before' => '',
		'format' => get_option( 'date_format' ),
		'label'  => '',
	);

	$atts = shortcode_atts( $defaults, $atts, 'post_date' );
		
	$display = ( 'relative' === $atts['format'] ) ? genesis_human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . ' ' . __( 'ago', 'genesis' ) : get_the_time( $atts['format'] );
	
	$new_output = sprintf( '<time %s>', genesis_attr( 'entry-time' ) ) . '<a rel="bookmark" href="' . get_permalink() . '">' . $display . '</a>' . '</time>';
	
	return $new_output;
}

Thanks Gary Jones for help with the filter!

Filed Under: Genesis Tagged With: entry footer, entry header, shortcode

Modifying the $content_width variable in Genesis

March 21, 2014 By David Wang

WordPress looks for the $content_width variable when determining the width of oEmbed items. To define this variable, you would put this in the functions.php file:

if ( ! isset( $content_width ) )
	$content_width = 600;

However this is kind of limiting especially since we can have multiple layouts in Genesis. So the Genesis team has made it easy to define different $content_widths. For Genesis child themes, we would use this instead:

$content_width = apply_filters( 'content_width', 580, 480, 900 );

The 3 numbers correspond to the content width of the default, small and large layouts. The default layout refers to 2-column layouts; small refers to 3-column layouts and large refers to the full-width content layout.

You can combine this with the following method (borrowed from Twenty Twelve) to apply a different $content_width to different contexts and page templates.

function twentytwelve_content_width() {
	if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) {
		global $content_width;
		$content_width = 960;
	}
}
add_action( 'template_redirect', 'twentytwelve_content_width' );

See also: Brad Dalton on How To Change Content Width For Media Embeds Conditionally

Filed Under: Genesis Tagged With: media, oembed, page layouts

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to Next Page »

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