Menu

Snippets

A Collection of Genesis code snippets


Switch Genesis Default Sidebars with markup

This snippet is for Sidebar Sidebar Content Layout and will swap places of the wider and narrow sidebars.

add_action( 'genesis_before', 'gt_switch_sidebars' );
function gt_switch_sidebars() {
    $site_layout = genesis_site_layout();
    if ( $site_layout == 'sidebar-sidebar-content' ) {
        remove_action( 'genesis_after_content', 'genesis_get_sidebar' );
        remove_action( 'genesis_after_content_sidebar_wrap', 'genesis_get_sidebar_alt');
        add_action( 'genesis_after_content', 'genesis_get_sidebar_alt' );
        add_action( 'genesis_after_content_sidebar_wrap', 'genesis_get_sidebar');
   }
}

You may need to modify your child theme’s style.css in order to fit the swapped sidebars. For the default example child theme find #content-sidebar-wrap and change the width to 640px

*Bonus

Two snippets for the price of one :)

With a big change like this to the layout I would suggest registering a new layout to use for this code. Simply Register a new layout with:

 
genesis_register_layout( 'sidebarwide-sidebar-content', array(
    'label' => 'Wide Sidebar/Sidebar/Content',
    'img' => CHILD_URL . '/images/wssc.gif',
) );

With the new registered layout use sidebarwide-sidebar-content in place of sidebar-sidebar-content in the switch function.

Use the image above to just give it that extra touch ( place the image in your child theme’s images folder ).

Short link:

Reverse Genesis loop order

remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'custom_loop');
function custom_loop() {

    global $paged;
    $args = array( 'order' => 'asc');
    genesis_custom_loop( $args );

}
Short link: http://goo.gl/mOvXq

Remove Navigation Only On the Homepage

add_filter('genesis_options', 'gt_no_nav_home', 10, 2);
function gt_no_nav_home($options, $setting) {
	if($setting == GENESIS_SETTINGS_FIELD) {
	if ( is_home() ) {
		$options['nav'] = 0;
		$options['subnav'] = 0;
		}
	}
	return $options;
}


This snippet was requested by the “Suggest a Tutorial ” form in the right side of the site. If you have an idea for a tutorial or a snippet please suggest something.

Short link: http://goo.gl/Mb71R

Add a .wrap to #inner

add_action('genesis_before_content_sidebar_wrap',  'gt_inner_wrap_open');
function gt_inner_wrap_open() {
     echo '<div class="wrap">';
}
add_action('genesis_before_footer',  'gt_inner_wrap_close');
function gt_inner_wrap_close() {
     echo '</div>';
}
Short link: http://goo.gl/UXFWr

Set default images for categories

add_filter('genesis_get_image','default_category_image');
function default_category_image($output) {
if ( !$output ) {
	if ( in_category('1') ) {
		$output = '<img height="150" width="200" title="default-categoryone-image" alt="default-categoryone-image" class="'alignleft post-image" src="'.get_bloginfo('stylesheet_directory').'/images/cat-thumbs/categoryone-graphic.png">';
	}
	elseif ( in_category('2') ) {
		$output = '<img height="150" width="200" title="default-categorytwo-image" alt="default-categorytwo-image" class="'alignleft post-image" src="'.get_bloginfo('stylesheet_directory').'/images/cat-thumbs/categoryone-graphic.png">';
	}
}
return $output;
}

Function Info: add_filter(), get_bloginfo(), genesis_get_image()

Short link: http://goo.gl/wRUxH

Change the favicon.ico Path

add_filter('genesis_favicon_url', 'custom_favicon_url');
function custom_favicon_url() {
	$favicon =  site_url("favicon.ico");
	return $favicon;
}

Function Info: add_filter(), site_url(), genesis_load_favicon()
Function Info: genesis_favicon_url

Short link: http://goo.gl/OUPBl

Two Custom Loops: One For Sticky Posts and One Without


remove_action('genesis_loop', 'genesis_do_loop');

add_action('genesis_loop', 'custom_sticky_loop', 9);
function custom_sticky_loop() { 
	if ( !is_paged() ) {
	
		// Get all sticky posts
		$sticky = get_option( 'sticky_posts' );
		// Sort the stickies with the newest ones at the top
		rsort( $sticky );  
		// Query sticky posts
		$args = array( 
			'post__in' => $sticky, 
			'caller_get_posts' => 1,
			'showposts' => -1 
		);
	
		genesis_custom_loop( $args );
		
		
	}
}


add_action('genesis_loop', 'custom_loop');
function custom_loop() {

    global $paged;
    // No sticky posts in this loop
    $args = array(
    	'post__not_in' =>get_option("sticky_posts"),
    	'paged' => $paged
    );
	
    genesis_custom_loop( $args );

}
Short link: http://goo.gl/CWefV

Genesis Homepage Teaser Boxes

Plug-in now available – Download: Genesis Post Teasers

The code below will add a box under Genesis > Theme Settings to enable or disable teaser boxes and after how many posts do you wish to be displayed in full before the teaser boxes.

[Read more...]

Short link: http://goo.gl/yTQoF

Remove "Purchase Themes" from the Genesis Menu

remove_theme_support( 'genesis-purchase-menu' );
Short link: http://goo.gl/fIsNp

Remove “Purchase Themes” from the Genesis Menu

remove_theme_support( 'genesis-purchase-menu' );
Short link: http://goo.gl/fIsNp

Remove the Genesis Menu

remove_theme_support('genesis-admin-menu');
Short link: http://goo.gl/NKlSt

Force Genesis Child Theme Home Layout

The snippet below will force the homepage layout of your child theme.

New Way

add_filter('genesis_pre_get_option_site_layout', 'custom_home_layout');
function custom_home_layout($opt) {
    if ( is_home() )
    $opt = 'full-width-content';
    return $opt;
}

Old Way

add_filter('genesis_options', 'custom_home_layout', 10, 2);
function custom_home_layout($options, $setting) {
	if($setting == GENESIS_SETTINGS_FIELD) {
		if(is_home())
		$options['site_layout'] = 'full-width-content';
	}
	return $options;
}

* Note This code can be used to force the layout for pages, categories, archives and page templates. Just change is_home() to the conditonal you want. For use in a custom page template files just include it before genesis():

Layout Options:
content-sidebar Content/Sidebar
content-sidebar-sidebar Content/Sidebar/Sidebar
sidebar-sidebar-content Sidebar/Sidebar/Content
sidebar-content-sidebar Sidebar/Content/Sidebar
full-width-content Full Width Content

Short link: http://goo.gl/UH0Rl

Custom Credit Text

add_filter('genesis_footer_creds_text', 'custom_footer_creds_text');
function custom_footer_creds_text($creds) {
 $creds = '[footer_copyright]' . get_bloginfo('name') . ' &bull; Built on the [footer_genesis_link]';
 return  $creds;
}
Short link: http://goo.gl/x7J0t