Genesis Quick Tips

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)

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk

Reader Interactions

Comments are closed. Continue the conversation with me on Twitter: @billerickson

Comments

  1. Frank Polack says

    Hi. Just stumbled upon this page. I’m a newbie at making mods to my Genesis site. Most of what I’m doing is through trial and error.

    My latest issue is that when I enter a site title in the Genesis theme setup, it displays correctly at the top of my browser tab, but it also appears at the top of my home page, under the primary nav.
    I have searched for the code where this is displayed, both in the child as well as the framework, and cannot find it anywhere to disable.
    could you suggest a quick fix for this?

    any help is appreciated.

  2. Jet says

    Hi Bill,
    May I ask a dumb question – What “15” stands for/means in the following code?

    add_action(‘genesis_setup’,’child_theme_setup’, 15);

    I tried to figure it our myself but didn’t know what to search for. Thank you very much!
    Jet

    • Bill Erickson says

      The third parameter is position. The default is 10. The higher the number, the later the function happens on that hook.

      I’m using 15 on that hook to ensure my child_theme_setup() function runs after anything else hooked on ‘genesis_setup’.

      A better example is positioning something before or after the nav menu. genesis_do_nav() is hooked to ‘genesis_after_header’, and since there’s no position specified, it is on the default ’10’ position. If you want something to show up right before it, do add_action( 'genesis_after_header', 'be_my_custom_code', 5 ); If you want something after it, use add_action( 'genesis_after_header', 'be_my_custom_code', 15 );

      • Bill Erickson says

        If two functions have the same priority, they are executed in the order WordPress sees them.

        Since the code in my setup function runs after Genesis is setup, hooking a function into ‘genesis_after_header” would run after the nav menu with either a priority of 10 or no priority specified (so it defaults to 10)

        Another example: If you hook three things to ‘genesis_after_header’ in your theme with the same priority, they show up in the order they appear in your functions.php file.

  3. Brad Dalton says

    Thanks Bill. Just tested that and both execute after the nav menu which has priority on that hook.

    Didn’t no that “Another example: If you hook three things to ‘genesis_after_header’ in your theme with the same priority, they show up in the order they appear in your functions.php file.”

    So i guess the primary nav menu executes first because thats the default in the Genesis core and everything else comes after unless you add a priority below 10.

    Cheers

    • Bill Erickson says

      Correct. Since all of your code runs after Genesis runs (you wouldn’t be able to use Genesis hooks unless its code has run already), any time you have a function with the same priority as a Genesis one, the Genesis one will run first.

  4. Jesse Vargas says

    Hey Bill
    How do I totally remove the “Return to top of page”? This is located at the bottom left of the page. Thanks in advance!

  5. Ezra Verheijen says

    Thanks Bill !

    Just one comment regarding the “Italicize “of” in Site Title” filter function:
    This code will also produce an unwanted title attribute:
    <a href title="...of...">...of...

    Why not use something like:

    remove_action( ‘genesis_site_title’, ‘genesis_seo_site_title’ );
    add_action( ‘genesis_site_title’, ‘ezra_seo_site_title’ );
    function ezra_seo_site_title() {
    echo ‘Bill Erickson‘;
    }

    or how I like to do it:

    remove_action( ‘genesis_site_title’, ‘genesis_seo_site_title’ );
    add_action( ‘genesis_site_title’, function() {
    echo ‘Bill Erickson‘;
    } );

    In my opinion it gives cleaner and better to reade code when using anonymous functions.

  6. Dan says

    If I wanted to pass an image in instead of text for the Search button, would I use $image as an argument and <img src="…. for the esc_attr?

    • Bill Erickson says

      I usually use add_filter( 'genesis_search_button_text', '__return_false' ); and then use CSS to style the image as the button.

  7. Zach E says

    Hey Bill — thanks so much for al these great Genesis tips! I used a few of them to restructure the location of my header and menu bars on this page http://doctorklaper.com/wp/ — BUT I ran into a problem and was hoping you had some feedback.

    Essentially I’m using the Going Green theme — everything is pretty standard, but my header image keeps on getting cut off by some other element on the page — I’ve tried FireBug to identify and eliminate the conflict but keep hitting brick walls.

    I also tried to move the main nav below the header (and I also tried to add it at the bottom of the page)— but when I did that, it lost it’s background color and has basically been hidden by the main body content.

    Any ideas/help are much appreciated!

    -Zach

  8. Josh Spurlock says

    Love your title toggle plugin. Is there a simple way to get it to apply to posts as well? I’m looking for basically the same functionality that exists for the pages for posts also.

  9. C R says

    Thanks so much. I’ve found your website really resourceful and helpful.
    I’m trying to understand why it’s worthwhile to unregister sidebars/footers/widgets.. Is it so that there is just less going on and/or does it affect the site’s speed?

    • Bill Erickson says

      Just to clean up the interface, and to ensure the site functions properly. If you build the site without a footer widget area but leave the widget area accessible, a client/user might add a widget to it and an unstyled footer widget area would appear. So you should remove the areas for which you are not supporting or testing.