List of Genesis snippets for customizing child theme

,

List of Genesis snippets for customizing child theme

Genesis is one of the best frameworks available for WordPress. It is one of the few frameworks that have a lot of hooks and actions for custom design features. You can easily change anything using the base framework and all in all it makes a really good custom experience if you have used Genesis framework as a base for designing your website. Recently we did a major redesign and re-branding and for this we used the Genesis framework and designed a custom child theme from base. A lot of code snippets are available for Genesis in order to customize child themes. So today we give to you at Inspire2rise a list of Genesis snippets for customizing child theme. So just scroll down a little bit in order to find these resources.

Code Snippets for Genesis

Here we aim to provide you with a comprehensive code snippets list for Genesis that would come in handy to you during the development process. So the list starts now, and all of the given below code snippets have to be added to the functions.php file for the child theme unless explicitly stated to put somewhere else.

  • Genesis Code snippet for HTML 5 markup:
//* Add HTML5 markup structure
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' ) );
  • Genesis code snippet for adding support for structural wraps:
//* Add support for structural wraps
add_theme_support( 'genesis-structural-wraps', array(
	'header',
	'nav',
	'subnav',
	'site-inner',
	'footer-widgets',
	'footer'
) );
  • Genesis Code snippet for enforcing a default layout:
//* Force content-sidebar layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar' );

//* Force sidebar-content layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_content' );

//* Force content-sidebar-sidebar layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_content_sidebar_sidebar' );

//* Force sidebar-sidebar-content layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_sidebar_content' );

//* Force sidebar-content-sidebar layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_sidebar_content_sidebar' );

//* Force full-width-content layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
  • Genesis Code snippet to remove a layout:
//* Remove content/sidebar layout
genesis_unregister_layout( 'content-sidebar' );
 
//* Remove sidebar/content layout
genesis_unregister_layout( 'sidebar-content' );
 
//* Remove content/sidebar/sidebar layout
genesis_unregister_layout( 'content-sidebar-sidebar' );
 
//* Remove sidebar/sidebar/content layout
genesis_unregister_layout( 'sidebar-sidebar-content' );
 
//* Remove sidebar/content/sidebar layout
genesis_unregister_layout( 'sidebar-content-sidebar' );
 
//* Remove full-width content layout
genesis_unregister_layout( 'full-width-content' );
  • Genesis Code Snippet to remove in post layouts:
//* Remove inpost layouts
remove_theme_support( 'genesis-inpost-layouts' );
  • Genesis Code Snippet for removing the widget area present in the site header:
//* Remove the header right widget area
unregister_sidebar( 'header-right' );
  • Genesis Code Snippet for removing Site Title present in the Site header:
//* Remove the site title
remove_action( 'genesis_site_title', 'genesis_seo_site_title' );
  • Genesis Code Snippet for removing the site description from the Site header:
//* Remove the site description
remove_action( 'genesis_site_description', 'genesis_seo_site_description' );
  • Genesis Code Snippet for removing the primary sidebar:
//* Remove the primary sidebar
unregister_sidebar( 'sidebar' );
  • Genesis Code Snippet for removing the secondary sidebar:
//* Remove the secondary sidebar
unregister_sidebar( 'sidebar-alt' );
  • Genesis Code Snippet for customizing the input box text inside the search form:
//* Customize search form input box text
add_filter( 'genesis_search_text', 'bg_search_input_text' );
function bg_search_input_text( $text ) {
    
	return esc_attr( 'Search my website...' );

}
  • Genesis Code Snippet for customizing the label text in the search form:
//* Customize search form label
add_filter( 'genesis_search_form_label', 'bg_search_form_label' );
function bg_search_form_label ( $text ) {

	return esc_attr( 'Search Form' );

}
  • Genesis Code Snippet for customizing text for submit button in the search form:
//* Customize search form submit button text
add_filter( 'genesis_search_button_text', 'bg_search_form_button_text' );
function bg_search_form_button_text( $text ) {

	return esc_attr( 'Search' );

}
  • Genesis Code Snippet for adding post formats:
//* Add support for post formats
add_theme_support( 'post-formats', array(
	'aside',
	'audio',
	'chat',
	'gallery',
	'image',
	'link',
	'quote',
	'status',
	'video'
) );
  • Genesis Code Snippet for adding post format images: 
//* Add post format images
add_theme_support( 'genesis-post-format-images' );
  • Genesis Code Snippet for removing post format images:
//* Remove post format images
remove_action( 'genesis_entry_header', 'genesis_do_post_format_image', 4 );
  • Genesis Code Snippet for removing Primary navigation menu:
//* Remove primary navigation menu
add_theme_support( 'genesis-menus', array( 'secondary' => __( 'Secondary Navigation Menu', 'genesis' ) ) );
  • Genesis Code Snippet for removing the Primary/Secondary navigation menus:
//* Remove primary/secondary navigation menus
remove_theme_support( 'genesis-menus' );
  • Genesis Code Snippet for removing the Secondary Navigation Menu:
//* Remove secondary navigation menu
add_theme_support( 'genesis-menus', array( 'primary' => __( 'Primary Navigation Menu', 'genesis' ) ) );
  • Genesis Code Snippet for repositioning Primary Navigation menu:
//* Reposition the primary navigation menu
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_before_header', 'genesis_do_nav' );
  • Genesis Code Snippet for repositioning Secondary Navigation Menu:
//* Reposition the secondary navigation menu
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_before_header', 'genesis_do_subnav' );
  • Genesis Code Snippet for pagination on single post pages, i.e. code to add previous and next post links + code for customizing the links:
//* Add previous and next post links after entry
add_action( 'genesis_entry_footer', 'genesis_prev_next_post_nav' );

//* Customize the next page link in the entry navigation
add_filter ( 'genesis_next_link_text' , 'bg_next_page_link' );
function bg_next_page_link ( $text ) {

	return 'Next Page »';

}
//* Customize the previous page link in the entry navigation
add_filter ( 'genesis_prev_link_text' , 'bg_previous_page_link' );
function bg_previous_page_link ( $text ) {
 
	return '« Previous Page';
 
}
  • Genesis Code Snippet for customizing the entry meta inside entry header:
//* Customize the entry meta in the entry header
add_filter( 'genesis_post_info', 'bg_entry_meta_header' );
function bg_entry_meta_header($post_info) {

	$post_info = '[post_date] by [post_author_posts_link] [post_comments] [post_edit]';
	return $post_info;

}
  • Genesis Code Snippet for removing the entry meta inside entry header:
//* Remove the entry meta in the entry header
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
  • Genesis Code Snippet to remove the entry title in the Entry header:
//* Remove the entry title in the entry header
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
  • Genesis Code Snippet for removing the post format image inside entry header:
//* Remove the post format image in the entry header
remove_action( 'genesis_entry_header', 'genesis_do_post_format_image', 4 );
  • Genesis Code Snippet for customizing entry meta in the entry footer:
//* Customize the entry meta in the entry footer
add_filter( 'genesis_post_meta', 'bg_entry_meta_footer' );
function bg_entry_meta_footer($post_meta) {

	$post_meta = '[post_categories] [post_tags]';
	return $post_meta;

}
  • Genesis Code Snippet for removing the entry meta inside entry footer:
//* Remove the entry meta in the entry footer
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
  • Genesis Code Snippet for creating custom comment respond title:
//* Customize the comment respond title
add_filter( 'comment_form_defaults', 'bg_comment_respond_title' );
function bg_comment_respond_title( $defaults ) {

	$defaults['title_reply'] = __( 'Thoughts', 'bg' );
	return $defaults;

}
  • Genesis Code Snippet to create custom submit button text in entry comments:
//* Customize the submit button text in comments
add_filter( 'comment_form_defaults', 'sp_comment_submit_button' );
function sp_comment_submit_button( $defaults ) {

	$defaults['label_submit'] = __( 'Submit Comment', 'bg' );
	return $defaults;
 
}
  • Genesis Code Snippet for customizing the size of Gravatar in Entry comments:
//* Customize the Gravatar size in the entry comments
add_filter( 'genesis_comment_list_args', 'bg_comments_gravatar' );
function bg_comments_gravatar( $args ) {

	$args['avatar_size'] = 96;
	return $args;

}
  • Genesis Code Snippet for adding Author box on archive pages (not single post):
//* Add the author box on single posts
add_filter( 'get_the_author_genesis_author_box_archive', '__return_true' );
  • Genesis Code Snippet for creating custom Author box title:
//* Customize the author box title
add_filter( 'genesis_author_box_title', 'bg_custom_author_box__title' );
function bg_custom_author_box__title() {
    
	return '<h1>About the Author</h1>';

}
  • Genesis Code Snippet for adding author box on single post pages:
//* Add the author box on single posts
add_filter( 'get_the_author_genesis_author_box_single', '__return_true' );
  • Genesis Code Snippet for removing Author box from Single post pages:
//* Remove the author box on single posts
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );
  • Genesis Code Snippet for customizing the size of Gravatar in the Author box: 
//* Customize the Gravatar size in the author box
add_filter( 'genesis_author_box_gravatar_size', 'bg_author_box_gravatar' );
function bg_author_box_gravatar( $size ) {
    
	return '96';
	
}

See more: How to pin a post to homepage in WordPress

  • Genesis Code Snippet for custom Author Box title:
//* Customize the author box title
add_filter( 'genesis_author_box_title', 'bg_custom_author_box__title' );
function bg_custom_author_box__title() {
    
	return '<h1>About the Author</h1>';

}
  • Genesis Code Snippet to force CSS changes to go live immediately, i.e. CSS Cache buster:
/** CSS Cache Buster */
define( 'CHILD_THEME_VERSION', filemtime( get_stylesheet_directory() . '/style.css' ) );

The above code changes the child theme version number to the last modified date of the style.css file. So whenever any modification is done, the URL path to stylesheet changes and hence the browser cache is busted and changes appear almost instantly.

  • Genesis Code Snippet to reposition sharing links provided by Jetpack:
/** 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 );
 
}

The above snippet has been taken courtesy of this tutorial by Ryan Meier.

my precious image inspire2rise joke
Just a random Lord of the Rings reference to break the monotony! 😛
  • Genesis Code Snippet to replace standard loop with custom loop:
/** 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) );
 
}
  • Genesis Code Snippet for changing the Genesis default favicon:
function child_load_favicon() {
 echo '<link rel="Shortcut Icon" href="' . get_stylesheet_directory_uri() . '/images/favicon.ico" type="image/x-icon" />'
}
  • Genesis Code Snippet for conditional CSS Classes for Internet Explorer:
/** 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
}

After adding the above code IE specific CSS can easily be added like the below example:

div.foo { color: inherit;}
.ie6 div.foo { color: #27bad9; }

The above snippet has been taken from Paul Irish’s article on the same.

  • Genesis Code Snippet for defining default post thumbnail:
/** 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;
 }
}

The above code will work when you have already placed a default image with the name thumb.jpg in the /images folder of your child theme. This code snippet was provided here by courtesy of Lori Berkowitz.

See more: Post penguin SEO strategies

  • Genesis Code Snippet to add page content to the top of a page using Blog page default template:
<?php

//* Template Name: Blog

//* Show page content above posts
add_action( 'genesis_loop', 'genesis_standard_loop', 5 );

genesis();

The above code has to be added in a custom file created in the child theme directory. The file can be called as page_blog.php and the above content should be present in that file and it shouldn’t be added to the functions.php file.

  • Genesis Code Snippet to modify “Read more” link shown in WordPress ‘More’ tag:
//* Modify the WordPress read more link
add_filter( 'the_content_more_link', 'sp_read_more_link' );
function sp_read_more_link() {
	return '<a class="more-link" href="' . get_permalink() . '">[Continue Reading]</a>';
}
  • Genesis Code Snippet to modify “read more” link that shows up when you are using Content Limit on the Content Archives section shown on the Genesis Settings page:
//* Modify the Genesis content limit read more link
add_filter( 'get_the_content_more_link', 'sp_read_more_link' );
function sp_read_more_link() {
	return '... <a class="more-link" href="' . get_permalink() . '">[Continue Reading]</a>';
}

In the above snippet you can change the ‘Continue Reading’ to any word/phrase of your choice.

  • Genesis Code Snippet for changing the length of post excerpts shown:
//* Modify the length of post excerpts
add_filter( 'excerpt_length', 'sp_excerpt_length' );
function sp_excerpt_length( $length ) {
	return 40; // pull first 40 words
}
  • Genesis Code Snippet to add a View port Meta tag to the site: 
//* Add Viewport meta tag for mobile browsers (requires HTML5 theme support)
add_theme_support( 'genesis-responsive-viewport' );
  • Genesis Code Snippet to add custom view port meta tag for mobile browsers:
//* Add custom View Port meta tag for mobile browsers
add_action( 'genesis_meta', 'sp_viewport_meta_tag' );
function sp_viewport_meta_tag() {
	echo '<meta name="viewport" content="width=device-width, initial-scale=1.0"/>';
}
  • Genesis Code Snippet to modify the Home link in Breadcrumbs:
//* Modify Home breadcrumb link.
add_filter ( 'genesis_home_crumb', 'sp_breadcrumb_home_link' ); // Genesis >= 1.5
add_filter ( 'genesis_breadcrumb_homelink', 'sp_breadcrumb_home_link' ); // Genesis =< 1.4.1
function sp_breadcrumb_home_link( $crumb ) {
	return preg_replace('/href="[^"]*"/', 'href="http://example.com/home"', $crumb);
}

 

Change the domain URL and other things in the above snippet according to your own preference.

  • Genesis Code Snippet for repositioning the breadcrumbs:
//* Reposition the breadcrumbs
remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' );
add_action( 'genesis_after_header', 'genesis_do_breadcrumbs' );
  • Genesis Code Snippet for modifying breadcrumbs display: 
//* Modify breadcrumb arguments.
add_filter( 'genesis_breadcrumb_args', 'sp_breadcrumb_args' );
function sp_breadcrumb_args( $args ) {
	$args['home'] = 'Home';
	$args['sep'] = ' / ';
	$args['list_sep'] = ', '; // Genesis 1.5 and later
	$args['prefix'] = '<div class="breadcrumb">';
	$args['suffix'] = '</div>';
	$args['heirarchial_attachments'] = true; // Genesis 1.5 and later
	$args['heirarchial_categories'] = true; // Genesis 1.5 and later
	$args['display'] = true;
	$args['labels']['prefix'] = 'You are here: ';
	$args['labels']['author'] = 'Archives for ';
	$args['labels']['category'] = 'Archives for '; // Genesis 1.6 and later
	$args['labels']['tag'] = 'Archives for ';
	$args['labels']['date'] = 'Archives for ';
	$args['labels']['search'] = 'Search for ';
	$args['labels']['tax'] = 'Archives for ';
	$args['labels']['post_type'] = 'Archives for ';
	$args['labels']['404'] = 'Not found: '; // Genesis 1.5 and later
return $args;
}

These were few of the amazing code snippets available for Genesis. Using these it’s possible to customize any child theme to an extra ordinary extent. This guide borrows liberally from Studiopress, Genesis Snippets and Brian Gardner‘s website.

We hope that you found this post informative and will share this resource with all Genesis fans that you might know. We spend a lot of time curating these and only included the most useful and handy snippets for Genesis child theme customization. If you liked this post then don’t forget to share it across your social networks and comment on it!

Keep visiting for more blogging tips, how to guides, lifestyle tips, and remember we cover, “Everything under the Sun!”




inspire2rise mascots - cowboys

Follow Inspire2rise on Twitter. | Follow Inspire2rise on Facebook. | Follow Inspire2rise on Google+.

Stay Inspired to rise fellas!

Read more Blogging articles on Inspire2rise:

 

 

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Written by Aditya Nath Jha

Aditya Nath Jha is an Engineer from New Delhi, India. His areas of interest include Gadgets, WordPress, speed optimization & latest technology.
When he is not busy blogging he loves to write poetry, compose his own songs and has a taste for music! Find me on Facebook, Google +, Twitter, Linked in.
And watch my videos on Youtube.

Comments

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading…

Facebook Comments

google pagesepeed shutting down change dns soon inspire2rise

Google Pagespeed service shuts down, change your DNS

Android M arriving soon, Android 5.1.1 update out

Android M arriving soon, Android 5.1.1 update out