Genesis Framework Snippets

I’ve debated for several months whether or not to post my Genesis Framework snippets here. Usually we keep to material that makes it easier for clients to use and maintain their WordPress sites. This post, in contrast, will be a list of Genesis Framework snippets and tutorials that I use for developing child themes. I look forward to your feedback!

Standard (the big list of) Genesis Framework Snippets

dev.studiopress.com list of tutorials. Snippets below are in addition to those.

Customizing Admin UI

* Best list I’ve found so far for editing the admin UI is Bill Erickson’s
* Brian Gardner’s Admin Management snippets
* Nick Croft’s Adding Genesis sub-menu item

Add Custom Post Type

There are a lot of examples. This is the go-to list of arguments for them: this post by Justin Tadlock.

Head Section

Add a banner image from the page’s featured image. Fall back on a default image.

/** Add banner beneath header */
	//retrieve banner from thumbnail if it exists and if it is wide enough
	add_action( 'genesis_before_content_sidebar_wrap','big_data_after_header');
	function big_data_after_header() {  
	echo '';
 

Add 3rd nav with separate file

*Download example topnav.php.

// Add topnav section 
//@cedits: Education Child Theme author
add_action('genesis_before_header', 'dswp_include_topnav'); 
function dswp_include_topnav() {
    require(CHILD_DIR.'/topnav.php');
}

//remove nav 
//remove_action( 'genesis_after_header', 'genesis_do_nav' );
//remove_action( 'genesis_after_header', 'genesis_do_subnav' );
//relocate nav
//add_action('genesis_before_header', 'genesis_do_nav');

 

Add a second header to the blog section

//add secondary header to blog section 
add_action('genesis_before_content_sidebar_wrap','dswp_blog_title');
function dswp_blog_title() {
	if (is_page_template('page_blog.php') || is_archive() || is_single() ) { 
echo '';
 } }
 

Special Design Cases

Selectively Remove Page Title

* See Bill Erickson’s snippets to put this control in the hands of the client

//remove page title
add_action('genesis_before','remove_title');
	function remove_title() {
	if ( is_page('x') || is_page('xz') || is_page('xy') ) {
	remove_action('genesis_post_title','genesis_do_post_title');
	}
	}
 

Change the loop inside a template

Codex Query page has list of args.

//one post per page
add_action('genesis_before_loop', 'portfolio_loop');
function portfolio_loop() {
	global $query_string;
 	$args= array( 
		'posts_per_page' => '1',
		'paged' => get_query_var( 'page' ));
 	query_posts(wp_parse_args($query_string, $args));
	}
 

Re-arrange post Title, Image, Content & Change Image classes

//put image first, then title, then text
remove_action('genesis_post_title','genesis_do_post_title');
remove_action('genesis_post_content','genesis_do_post_image');
remove_action('genesis_post_content','genesis_do_post_content');

add_action('genesis_before_post_title','child_post_image');
add_action('genesis_post_title','genesis_do_post_title');
add_action('genesis_post_content','the_content');

//add classes to post image
//uses established image size "Portfolio"
//credit @nick croft
function child_post_image() { 
	$large_image_url = genesis_get_image( array( 'format' => 'url', 'size' => 'large'));
	  $img = genesis_get_image( array( 'format' => 'html', 'size' => 'portfolio', 'attr' => array( 'class' => 'alignleft post-image' ) ) );
        printf( '%s', $large_image_url, the_title_attribute('echo=0'), $img );
}  
 

Comments

Comments Header with #’s

Guessing here but it looks like code from Nick Croft. From StudioPress forums.

// Modify comments header text in comments
add_filter('genesis_title_comments', 'dswp_genesis_title_comments');
function dswp_genesis_title_comments() {
   $title = '

'; $title .= comments_number('No Comments on ', 'One Comment on ', '% Comments on ' ); $title .= the_title(); $title .= '

'; return $title; }

Edit Comments Form

//@credits Rebecca StudioPress Forums
//edit comments form text
add_filter('genesis_comment_form_args', 'custom_comment_form_args');
function custom_comment_form_args($args) {
   	 $args['title_reply'] = 'Join The Conversation';
	$args['comment_notes_before'] = ' 

All comments are moderated.

* Denotes required field.

'; $args['comment_field'] = '

' . '' . '' . '

'; return $args; }

Edit Comments Display

//Genesis Files
//edit comments callback 

function child_comment_callback( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment; 
	
	echo '
  • '; genesis_before_comment(); echo '
    '; echo get_avatar( $comment, $size = $args['avatar_size'] ); printf( __('%s', 'genesis'), get_comment_author_link(), apply_filters('comment_author_says_text', __('', 'genesis')) );?>
    comment_approved == '0') : ?>

    $depth, 'max_depth' => $args['max_depth']))); ?>
    tag because of comment threading } add_filter('genesis_comment_list_args', 'child_comment_list_args'); function child_comment_list_args($args) { $args['callback'] = 'child_comment_callback'; return $args; }
  • Page Navigation Functions

    Edit older/newer post nav text

    add_filter('genesis_older_link_text', 'dswp_older_link_text');
    function dswp_older_link_text($text) {
       return 'Older Listings';
    }
    
    add_filter('genesis_newer_link_text', 'dswp_newer_link_text');
    function dswp_newer_link_text($text) {
       return 'Newer Listings';
    }  
    

    Reverse “older/newer” post nav

    @credit: Nick Croft

    //Reverse older/newer post nav
    remove_action('genesis_after_endwhile', 'genesis_posts_nav');
    remove_action('genesis_after_endwhile','child_posts_nav');
    add_action('genesis_after_endwhile', 'portfolio_posts_nav');
    function portfolio_posts_nav() {
        $newer = get_previous_posts_link(__('previous', 'genesis'));
        $older = get_next_posts_link(__('next', 'genesis'));
         
        $nav = '
        
        ';
        
        if(!empty($newer) || !empty($older))
            echo $nav;
    } 
    

    Add Navigation to single post pages

    //add post nav to single post pages
    add_action ('genesis_before_post_title', 'post_navigation');
    function post_navigation() { 
     if (is_single()) { 
    	echo '';
      }} 
    

    Widgets & Widget Areas

    Insert MailChimp Signup Form

    Download sample newsletter.php here. Replace “xxx” with your unique MailChimp link.

    //add newsletter signup form
    require(CHILD_DIR.'/newsletter.php'); 
    

    Change home.php content

    //add widget areas to home page
    remove_action('genesis_loop', 'genesis_do_loop');
    add_action('genesis_loop', 'child_home_content');
    	function child_home_content() {
    		dynamic_sidebar('Home Content Area');
    	} 
    

    Misc

    Conditional for Child & GrandChild Pages

    Credit: WordPress codex

    //Credits: @wordpress codex
    function is_tree( $pid ) {      
    	global $post;
        if ( is_page($pid) )
            return true; 
        $anc = get_post_ancestors( $post->ID );
        foreach ( $anc as $ancestor ) {
            if( is_page() && $ancestor == $pid ) {
                return true;
            }}
        return false; 
        } 
    

    Comments

    1. CyBorge says:

      Thank you! Some very practical solutions to common problems. Good Karma for you my friend!

    2. That’s a very useful one, but to where exactly do we add these codes? secondly, is there any screenshot to help us know how exactly our sites will look like when we add the codes?

      Thanks

      • Cathy Tibbles says:

        These are a collection of snippets that I use as a developer in either new templates in the child theme or the child theme’s functions. for the complete guide on creating a child theme for Genesis – see the COMPLETE beginner’s guide at studiopress.com.

      • Cathy Tibbles says:

        These codes are meant for those who are familiar with creating child themes. You add these codes to ACTIONS within a function file in the child theme or to a custom template within the child theme. See the tutorial here: http://my.studiopress.com/docs/child-themes/ after logging in.

    3. Nice collection. Some codes are new…

    4. Very nice, thank you for the snippets! I’m still trying to figure out how to change the URL of portfolio pages in Genesis child themes to make it http://www.example.com/projects instead of http://www.example.com/portfolio. Do you know how that’s done?

      Thanks again!
      David

      • Cathy Tibbles says:

        Hi David,
        Create a new page, and give it the template “portfolio” if a template is available. If you’re creating your own custom page, just change the url (field located under the page title).

    Speak Your Mind

    *