• 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 CSS classes and IDs for Genesis menus

July 28, 2012 By David Wang

Here’s a quick code snippet to:

  1. Assign an ID to the menu
  2. Change the menu class
  3. Append to the menu class
add_filter( 'genesis_do_nav', 'override_do_nav', 10, 3 );
function override_do_nav($nav_output, $nav, $args) {

    $args['menu_id'] = 'the_id_you_want';
    $args['menu_class'] = 'class1 class2'; // replace what was there
    $args['menu_class'] .= ' class3'; // or append to it

    // check which function should be used to build the nav
    // rebuild the nav using the updated arguments
    if ( genesis_get_option( 'nav' ) ) {
        if ( has_nav_menu( 'primary' ) ) {          
            $nav = wp_nav_menu( $args );            
        } elseif ( 'nav-menu' != genesis_get_option( 'nav_type', 'genesis-vestige' ) ) {
            $nav = genesis_nav( $args );
        }
    }

    // return the modified result
    return sprintf( '%2$s%1$s%3$s', $nav, genesis_structural_wrap( 'nav', 'open', 0 ), genesis_structural_wrap( 'nav', 'close', 0 ) );

}

Credit: Evan Mattson and Daniel Zimmermann on WordPress.StackExchange.com – Using a filter to modify Genesis wp_nav_menu

Filed Under: Genesis Tagged With: menu, navigation

Define a default post thumbnail

May 23, 2012 By David Wang

Here’s how to define a default post thumbnail that works with Genesis’s genesis_get_image() function. Be sure to place a default image called thumb.jpg in your child theme’s images folder.

/** Define a default post thumbnail */
add_filter('genesis_get_image', 'default_image_fallback', 10, 2);
function default_image_fallback($output, $args) {
	global $post;
	if( $output || $args['size'] == 'full' )
		return $output;

	$thumbnail = CHILD_URL.'/images/thumb.jpg';

	switch($args['format']) {

		case 'html' :
			return '<img src="'.$thumbnail.'" class="attachment-'. $args['size'] .'" alt="'. get_the_title($post->ID) .'" />';
			break;
		case 'url' :
			return $thumbnail;
			break;
	   default :
		   return $output;
			break;
	}
}

Updated from Lori Berkowitz

See also: Nick the Geek’s tutorial – Genesis Explained Image Functions

Filed Under: Genesis Tagged With: featured image, images, post thumbnail

Change or remove the default favicon

May 7, 2012 By David Wang

Changing the favicon for your Genesis child theme is easy. Simply replace the default favicon file at

wp-content/child-theme/images/favicon.ico

If you want to remove the favicon altogether, use this line of code in your functions.php:


/** Remove favicon */
remove_action('genesis_meta', 'genesis_load_favicon');

Credit: Jennifer Baumann

Filed Under: Genesis Tagged With: branding, favicon

Customize comments HTML output

April 9, 2012 By David Wang

Sometimes you need to customize the HTML output of the WordPress comments_template(). Here’s how to do it in your Genesis child theme.

// First remove the genesis_default_list_comments function
remove_action( 'genesis_list_comments', 'genesis_default_list_comments' );

// Now add our own and specify our custom callback
add_action( 'genesis_list_comments', 'child_default_list_comments' );
function child_default_list_comments() {

	$args = array(
		'type'			=> 'comment',
		'avatar_size'	=> 54,
		'callback'		=> 'child_comment_callback',
	);

	$args = apply_filters( 'genesis_comment_list_args', $args );

	wp_list_comments( $args );

}

// This is where you customize the HTML output
function child_comment_callback( $comment, $args, $depth ) {

	$GLOBALS['comment'] = $comment; ?>

	<li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
		
		<?php do_action( 'genesis_before_comment' ); ?>
		
		<div class="comment-left">

			<div class="comment-author vcard">
				<?php echo get_avatar( $comment, $size = $args['avatar_size'] ); ?>
				<?php printf( __( '<cite class="fn">%s</cite> <span class="says">%s:</span>', 'genesis' ), get_comment_author_link(), apply_filters( 'comment_author_says_text', __( 'says', 'genesis' ) ) ); ?>
			</div><!-- end .comment-author -->
	
			<div class="comment-meta commentmetadata">
				<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><?php printf( __( '%1$s at %2$s', 'genesis' ), get_comment_date(), get_comment_time() ); ?></a>
				<?php edit_comment_link( __( 'Edit', 'genesis' ), g_ent( '&bull; ' ), '' ); ?>
			</div><!-- end .comment-meta -->
			
		</div>
		
		<div class="comment-right">	
	
			<div class="comment-content">
				<?php if ($comment->comment_approved == '0') : ?>
					<p class="alert"><?php echo apply_filters( 'genesis_comment_awaiting_moderation', __( 'Your comment is awaiting moderation.', 'genesis' ) ); ?></p>
				<?php endif; ?>
	
				<?php comment_text(); ?>
			</div><!-- end .comment-content -->
	
			<div class="reply">
				<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
			</div>
			
		</div>	

		<?php do_action( 'genesis_after_comment' );

	/** No ending </li> tag because of comment threading */

}

In the example above I split the comment into comment-left and comment-right to display it in a 2 column format. Of course, you could customize it more extensively than that. See also the official StudioPress tutorial on customizing comments. Happy hacking!

Filed Under: Genesis Tagged With: comments

Unregister sidebars

March 21, 2012 By David Wang

Don’t need the header right widget area? Or perhaps you don’t need 3 columns for your theme. Then your widget areas a.k.a. sidebars are redundant. Unregister them with the following:

/** Unregister default sidebars */
unregister_sidebar( 'header-right' );
unregister_sidebar( 'sidebar' );
unregister_sidebar( 'sidebar-alt' );

Filed Under: Genesis Tagged With: sidebars, widget areas

Register new widget areas

March 21, 2012 By David Wang

First, register a new sidebar. The before_widget, after_widget, before_title and after_title arguments are optional and allow you to customize the HTML output.

genesis_register_sidebar(
	array(
		'name'=>'Custom Sidebar',
		'id' => 'sidebar-custom',
		'description' => 'This is a custom sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widget-wrap">',
		'after_widget'  => "</div></div>",
		'before_title'  => '<h4 class="widgettitle">',
		'after_title'   => "</h4>"
	)
);

Then inject the sidebar into the appropriate hook with genesis_widget_area(). The function conditionally displays a widget area.

add_action( 'genesis_sidebar', 'child_do_sidebar' );
function child_do_sidebar() {
	genesis_widget_area( 'sidebar-custom',
		array(
			'before' => '<div id="sidebar-custom">',
		)
	);
}

See the available arguments for genesis_widget_area() in /genesis/lib/functions/widgetize.php

Update 28 Dec 2012: Replaced dynamic_sidebar() with genesis_widget_area()

Filed Under: Genesis Tagged With: sidebars, widget areas

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