There’s a lot of small code snippets I use often but don’t warrant their own post. This is where I’ll collect them. If you have any quick tips, feel free to share in the comments.
Also check my general code snippets page.
Setup the child theme
As described here, it’s a good idea to create a theme setup function in which you’ll place all the filters, actions, and theme-supported features. This is what I include at the top of my functions.php file in my child themes. Any time below you see an add_action or add_filter, that part goes in the setup function, and the function itself goes after the setup function.
Force a page layout
This is very useful for ensuring custom pages you build for a client aren’t broken by them changing the page layout (ex: home page). Or, changing the page layout to something other than the default on archive pages (ex: category).
Unregister unused page layouts
Structural Wrap
This adds a div with the class of “wrap” in an element. In the code below I’m adding it to #inner for a full-width page layout. More details.
Add Image Sizes
See Mark Jaquith’s postfor details. This adds an image size named ‘feature’ with a fixed size of 600×250.
add_image_size('feature', 600, 250, true);
Remove Post Info
remove_action('genesis_before_post_content', 'genesis_post_info');
Modify Post Info
Shortcode Reference
Remove Post Meta
remove_action('genesis_after_post_content', 'genesis_post_meta');
Modify Post Meta
Change Excerpt More text [...]
Remove Footer
remove_action('genesis_footer','genesis_do_footer');
Remove Footer and Footer Markup
(thanks Paul de Wouters)
Customize the Search Form text
Customize the Search Button text
Remove Breadcrumbs
remove_action('genesis_before_loop', 'genesis_do_breadcrumbs');
Remove Home from Breadcrumbs
add_filter('genesis_home_crumb', '__return_false');
Customize the Breadcrumb
Full list of arguments here.
Customize the Site Title (in #header)
This is useful if you want to use the default site title (Settings > Title) but style different elements of it differently. This specific code searches for “of” in the site title, and changes it to <em>of</em>.
Remove the Post Title
remove_action('genesis_post_title','genesis_do_post_title');
Display Description of Menu Items
To add a description to a menu item, go to Appearances > Menus. At the top right click “Screen Options”, then check “Description”. Now you can click the dropdown arrow next to menu items and add a description. The below code will make it visible on the site.
Register a Sidebar
Unregister a Sidebar
unregister_sidebar('sidebar-alt');
Customize Read More Link
CSS – Images scale to content area (useful for Responsive Design)


Great idea, Bill. I’ve got an Evernote notebook for this same thing.
All I can tell, is this is one of the best post about Genesis framework I ever seen. You did an excellent job explaining every snippets. One Snippet I use is:
add_filter(‘genesis_footer_backtotop_text’, ‘footer_backtotop_filter’);
function footer_backtotop_filter($backtotop) {
$backtotop = ‘[footer_backtotop text="write something here"]‘;
return $backtotop;
}
add_filter(‘genesis_footer_creds_text’, ‘footer_creds_filter’);
function footer_creds_filter($creds) {
$creds = ‘Copyright @ 2010 · website · Terms · Privacy Policy
‘;
return $creds;
}
Great but can I change this “2010″ to something automatic.
I’m not sure what you mean. Can you expand upon it?
If you’re looking to put the year in the footer (ex © 2011) and want it to auto update, use [footer_copyright]
Hey!
Do you know, how to ad the post title in the footer?
No matter if is a article site or home, or category/blog section.
I want to show the title of this page in my footer,too.
i tested ['genesis_post_title] and [genesis_do_post_title], nothing happens.
Post title isn’t one of the shortcodes that is set up ( http://dev.studiopress.com/shortcode-reference ). You could create your own shortcode though. Put this in functions.php:
Then you can use [post-title] as a shortcode anywhere in your site.
thaaaaanks!! IT works
There is only a small fail (on category or home section, it shows the title of the last entry in this section) but no matter!
THHHHHHHXXXXXXXXXXXX!!!!!!!!!!!!!!!!
Yes, the post title only works on individual posts. Here’s how to limit the [post-title] to only work on single posts
add_shortcode('post-title','post_title_shortcode');
function post_title_shortcode($atts) {
global $post;
if(is_single()) return get_the_title($post->ID);
}
Excellent post. By the way, if I want to add a background image to a navigation menu, how do I do that. I looked at the tutorial on Studiopress website but what I didn’t understand was, do I have to add something to the function.php file? Do I need to remove anything from style.css before adding the css for the new custom menu?
Thanks mate!
No, you shouldn’t have to edit the functions.php file. Inside style.css in your child theme you will modify the css relating to the nav menu. For example, you might add this:
#nav {background: url(‘images/nav-bg.jpg’) repeat-x;}
This saved my life today:
unregister_sidebar(‘sidebar’);
unregister_sidebar(‘sidebar-alt’);
Thank you Bill.
Love,
Greg
Haha I’m glad it helped. I use unregister_sidebar(‘sidebar-alt’) on almost every project.
thanks, very useful stuff. I’ll add them to my snippets collection!
Thanks for the “force layout” function, just allowed me to list employees along with the Genesis Grid Loop on a full width page:)
http://www.studiopress.com/support/showthread.php?p=291897&posted=1#post291897
to completely remove the footer, use this code :
// Remove Footer
remove_action(‘genesis_footer’, ‘genesis_do_footer’);
remove_action(‘genesis_footer’, ‘genesis_footer_markup_open’, 5);
remove_action(‘genesis_footer’, ‘genesis_footer_markup_close’, 15);
thank you ……its working…..
How can we add “href anchor link” to logo in any “genesis child theme”?
Thanks,
Kumar Sekhar
I’m not sure what you mean. The title is already wrapped in an anchor link, you just have to set the background image of that anchor link to be your logo.
Hello Bill,
It seems when using the menu descriptions snippet, it’s somehow affecting more then just the menu and menu widget.
In example it’s also affecting
function lorem() {
echo ‘lorem’;
}
add_action(‘genesis_after_header’, ‘lorem’, 15);
making ‘lorem’ a link
Ah, it seems removing the last slash did the trick
function child_nav_menu_start_el($item_output, $item, $depth, $args) {
$description = __($item->post_content);
return preg_replace(‘/([^<]*?)</', '$1' . '’ . $description . ‘<', $item_output);
}
add_filter('walker_nav_menu_start_el', 'child_nav_menu_start_el', 10, 4);
Just one question remaining
, do you perhaps know where the space before $description comes from? (and how to remove it)
In example it now lists: lorem
sorry lorem
Thanks for making me re-look at that code. Yes, the last slash was rendering , which made the link never close. Fixed.
I also removed the space in the span ( <span > to <span>) and made it so the description only shows up if there’s actually a description. By default the description is a blank space. So now I check to make sure $description is not a blank space before adding it.
Bill,
Thanks for sharing all of these code snippets. Glad I finally found this page. This is why I love the Genesis community.
Mark
Hello Bill,
I want to remove the title from breadcrumb. How can i do that.
e.g.
Blog » Tutorial » Genesis Quick Tips
should look like this:
Blog » Tutorial
I hope their will be any solution!!
Unfortunately this isn’t a simple change. You’ll need to completely rebuild the get_single_crumb() function in genesis/lib/classes/breadcrumb.php. Use the
genesis_single_crumbfilter.Where on earth do I paste these codes? I’m trying to remove the sidebar on my theme.
They belong in your theme’s functions.php file. But make sure you know what you’re doing. If you’re not careful it is easy to break the site. Also make sure you do not do this through the theme editor built into WordPress. If you paste something wrong your site will go down and you can’t access the backend.
I dont understand the “Force Page Layout” above, Bill… how does that apply to categories only? Wouldn’t that apply to everything? and what does the underscore before the option mean?
Yes, if you put it in functions.php it would apply to all pages, but if you put it in category.php then it applies only to the category archives, and in front-page.php only on the front page.
When using Genesis, think of each template file as a functions.php that applies to a subset of your pages.
Have got a lot of use out of this post! Thanks Bill…Cheers!
Hi. How do I exclude Homepage from showing breadcrumbs and still be able to show them on blog page?
Thanks!
1. Create a page called Home and a page called Blog
2. Go to Settings > Reading, set “Home” as the homepage and “Blog” as the posts page.
3. In functions.php, put this: https://gist.github.com/2046646
Hi Bill,
Thanks for all of these extremely useful snippets.
Regarding the ‘Remove Post Title’ snippet:
From everything I’ve read about SEO, the title tag is one of several important on page SEO factors.
So, at first I was worried about removing the titles – though I wanted to for appearance sake.
Howver, I noticed that when I use your snippet to remove the title, the Title tag is still intact in the page source, with the correct page title.
Do you know if using the ‘Remove the Post Title’ function adversely affects SEO?
Or, in your opinion does this method give us the best of both – no unsightly titles without forfeiting that SEO factor?
Kind Regards.
You’ll lose the h1 on the page, so that will affect your SEO. I only recommend using this if you plan to manually type in an h1 in the post content.
Hi I am relatively new to WordPress and I am working on a couple of sites at the minute. I was wondering if you could help me out Bill. I am using WordPress with the Genesis Framework and Genesis child theme. My Question is: ”How do I remove the Primary Sidebar from the home page only” I have been looking on the net for help and cannot seem to find anything that works. If you could help me out I would really appreciate it. Thanks
Try this: https://gist.github.com/2046500
If that doesn’t work, try changing is_home() to is_front_page()
Thanks for a great post Bill, I found this looking for something else but it has extended my Genesis knowledge. Thanks for sharing.
I’m having a heck of a time with something, and hope you can help. I want to remove all “Filed under” and “Tagged With” copy on the content archive pages. I want to leave that in all of the actual blog posts. How would I do this?
Thanks!
In functions.php, you’ll need to use the
genesis_post_infoandgenesis_post_metafilters to alter the post info/meta in the way you want. For instance, let’s say you want the categories and tags in the post meta, functioning as you describe: https://gist.github.com/2141539For information on the shortcodes and their parameters, see the Genesis Shortcode Reference
Awesome awesome tips – thank you so much for sharing! Already put a few of these to use.. Nice last name too
Thanks again!