• 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

Reposition Jetpack sharing links

June 13, 2013 By David Wang

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' ) )
		return;
	
	// 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' ) )
		return;
	
	// get the sharedaddy links html
	$sharedaddy_links = sharing_display();
	
	// if sharing_display() does not return anything, return
	if( empty( $sharedaddy_links ) )
		return;
	
	// 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

Filed Under: Genesis Tagged With: jetpack, plugin integration

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

Replace default loop with custom loop

September 15, 2012 By David Wang

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().

Filed Under: Genesis Tagged With: genesis_custom_loop, loop

Conditional CSS classes for IE in Genesis

August 31, 2012 By David Wang

Here’s how to implement Paul Irish’s solution for conditional IE CSS classes for the html tag in Genesis.

/** Conditional html element classes */
remove_action( 'genesis_doctype', 'genesis_do_doctype' );
add_action( 'genesis_doctype', 'child_do_doctype' );
function child_do_doctype() {
	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--[if lt IE 7 ]> <html class="ie6" xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes( 'xhtml' ); ?>> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7" xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes( 'xhtml' ); ?>> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8" xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes( 'xhtml' ); ?>> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9" xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes( 'xhtml' ); ?>> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class="" xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes( 'xhtml' ); ?>> <!--<![endif]-->
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php bloginfo( 'charset' ); ?>" />
	<?php
}

Now you can easily target IE in your CSS like so:

div.foo { color: inherit;}
.ie6 div.foo { color: #ff8000; }

Simple huh?

Filed Under: Genesis Tagged With: doctype, internet explorer

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

Force a layout in a template

July 29, 2012 By David Wang

Here’s a code snippet you can use when you want to lock down a layout for a specific template. Just drop the following into a single-posttype.php, template-something.php, etc before the genesis() function:

add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );

Note: __genesis_return_full_width_content is a helper function built into Genesis. See the end of this post on all available helper functions: Overriding Options and Meta.

Alternate method from Brad in the comments below which can go in functions.php:

/** Force full width layout */
add_filter( 'genesis_pre_get_option_site_layout', 'child_do_layout' );
function child_do_layout( $opt ) {
	if ( is_single() ) { // Modify the conditions to apply the layout to here
		$opt = 'full-width-content'; // You can change this to any Genesis layout
		return $opt;
	}
}

As a reminder, Genesis comes with 6 default layouts:

content-sidebar
sidebar-content
content-sidebar-sidebar
sidebar-sidebar-content
sidebar-content-sidebar
full-width-content

See Brian Gardner’s post on creating a landing page in Genesis for a practical example of how you would use this.

Updated: 17 June 2013

Filed Under: Genesis Tagged With: page layouts

  • « Go to Previous Page
  • 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