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. Here’s another, more detailed approach.
Register a Sidebar
Unregister a Sidebar
unregister_sidebar('sidebar-alt');
Customize Read More Link
CSS – Images scale to content area (useful for Responsive Design)
Rob R. says
Hi Bill,
Is there a simple way to customize the crumb for each page? For instance my About page title is very long and doesn’t look good in the breadcrumbs trail. It has children pages as well. So in the breadcrumbs I just want it’s crumb to be “About”, so various pages’ breadcrumbs would look like this:
Home > About
Home > About > Leadership
Home > About > Culture
I tried your code here: https://www.billerickson.net/adding-blog-to-genesis-breadcrumbs/ and added
if ( is_page( ‘2’))
$crumb = ‘About’;
but that doesn’t seem to do anything.
Thanks!
Rob
Bill Erickson says
I think the best approach would be to use the filter
genesis_page_crumb
to modify the page’s title in the breadcrumbs. Do a find/replace for the title. Something like: https://gist.github.com/billerickson/e4d359c39814513b397a134dff189f9aRob R says
Thanks so much for the quick reply!
Marco says
Hello Bill,
the recent Genesis v2.7.3 update broke my site search bar. The snippet I got from you years ago for removing text from the search button doesn’t work anymore:
add_filter( ‘genesis_search_button_text’, ‘__return_false’ );
I wanted to know if you’ve found a way for fixing it again.
Thank you in advance and happy holidays
Darlene says
And I’m experiencing the same failure of removing the post title link:
add_filter( ‘genesis_link_post_title’, ‘__return_false’ );
Bill Erickson says
Are you sure your theme is using the default
genesis_do_post_title()
function for outputting the post title? If your theme uses a custom function for displaying the post title on archives, that filter wouldn’t work because it probably doesn’t exist in your theme’s custom function.