Modifying the $content_width variable in Genesis

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

Reposition Jetpack sharing links

Love it or hate it, the Jetpack plugin offers one of the better options for enabling sharing links on your WordPress site. Unfortunately in Genesis the links are displayed in between the content and post meta. Here’s how to reposition the sharing links.

Place this code into functions.php

/** Custom positioning of Jetpack buttons */

// Remove the 'the_content' filter callback added by sharedaddy 
// to prevent the sharing links from being appended to the posts content.

add_action( 'init', 'custom_init', 11 );
function custom_init(){
	// if sharing_display() function does not exist, return
	if( ! function_exists( 'sharing_display' ) )
	// remove the callback sharing_display() for the 
	// 'the_content' and 'the_excerpt' filters.
	remove_filter( 'the_content', 'sharing_display', 19 );
	remove_filter( 'the_excerpt', 'sharing_display', 19 );

// Display sharedaddy buttons

add_action( 'genesis_before_post_content', 'child_do_sharedaddy' );
function child_do_sharedaddy(){
	global $post;
	// if sharing_display() does not exist, return
	if( ! function_exists( 'sharing_display' ) )
	// get the sharedaddy links html
	$sharedaddy_links = sharing_display();
	// if sharing_display() does not return anything, return
	if( empty( $sharedaddy_links ) )
	// create a template for the sharedaddy box content
	$template = '<div class="sharedaddy-box">%s</div>';
	// display the sharedaddy links within it's own box
	$content = sprintf( $template, $sharedaddy_links );
	// apply a filter for future adjustments
	echo apply_filters( 'sharedaddy_box_content', $content, $template, $sharedaddy_links );

In the above code we are displaying the buttons at the top of the post at the genesis_before_post_content hook. Reposition the buttons by hooking them on any of the other Genesis hooks.

Credit: Ryan Meier. The above code borrows liberally from his tutorial – Moving Jetpack Sharedaddy links outside the content with Genesis

See also: The Jetpack team has a blog post about this too – Moving Sharing Icons

Last modified: 27 June 2013

Display a custom sidebar on a custom post type

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
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

Replace default loop with custom loop

Genesis comes with a handy function called genesis_custom_loop(). It’s an easy way for you to create a new loop without having to write all the code to create a new loop with WP_Query manually. Here’s how you can use it in your theme.

/** Replace the standard loop with our custom loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'child_do_custom_loop' );

function child_do_custom_loop() {

	global $paged; // current paginated page
	global $query_args; // grab the current wp_query() args
	$args = array(
		'category__not_in' => 42, // exclude posts from this category
		'paged'            => $paged, // respect pagination

	genesis_custom_loop( wp_parse_args($query_args, $args) );


The above will spit out a loop that excludes posts from category ID 42 and displays posts from the current paginated page (i.e. /page/2 and so on). The wp_parse_args() function combines the $args array with the current $query_args for that page. The $args array should accept all WP_Query parameters.

Replace with a non-Genesis loop

If you need to completely customize the loop, if you are displaying events or a ecommerce shop page for example, you don’t need to use the genesis_custom_loop() function at all. Just write your own to replace it.

/** Code for custom loop */
function my_custom_loop() {
	// code for a completely custom loop

/** Replace the standard loop with our custom loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'my_custom_loop' );

You can stick this code in functions.php to affect all the loops in your site, or put it in a template file like date.php or author.php to limit it with the template hierarchy. If you do stick it in a template file, remember to end it with genesis().