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 a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

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

Let's Talk

Reader Interactions

Comments

  1. Nur Ahmad Furlong says

    Thanks for this very helpful list of snippets like all your others. It’s a constant struggle when you’re not able to really dig deep into genesis to know how to target certain elements and even what they’re called to begin with so having snippets by guys like you make all the difference.

    I’ve been scouting around trying to find a way of inserting genesis breadcrumbs into a very customized single CPT template. Because the template is so highly customised it uses very little actual genesis code but now I realise the need to try to do any custom stuff in a very genesis way.
    Does anyone know if there are ways of inserting genesis template parts manually into non-genesis templates?

    My theme is mostly genesis but one or 2 of the custom page templates are more pure wp based.

    Additionally any help in tracking down tuts which cover custom post type “single” templates would be great, so far the majority of advanced tuts tackle archives.

  2. Mario says

    How can i change [post_categories] variable?

    I’d like to have “Published on” [post_date] in [post_categories] where [post_categories] = categories and not “Filed under:” + categories.

    I’d like also to filter info and meta to apply only on homepage or singlepost/archies, not globally.

    • Bill Erickson says

      Use [post_date before="Published on "] [post_categories before="in "].

      In your post info or post meta filter, you can use conditionals. if( is_home() ) $post_info = '';

  3. Chris Field says

    Hi Mr. Erickson,

    Could you provide a little background on your use of “genesis_setup” with “child_theme_setup” (first snippet on this page) as opposed to using “include_once( get_template_directory()” to launch the Genesis init.php file? As in:
    https://github.com/gregrickaby/genesis-sample/blob/sass/functions.php

    Your method appears to better follow the WordPress standard, however the latter method is what Genesis uses in its child themes.

    I have not been able to discern much of a difference between the two approaches, aside from maybe conforming to that WordPress standard.

    Would be very grateful for your thoughts on the two approaches!

  4. Scott says

    Bill:

    I’m trying to change the title to the search results page on a child theme, but the script is in genesis search.php
    I would like the search title to be “Listing Results” and perhaps include the query that was made i.e. “Listing Results for 3 bdrm 2 bath”
    I’ve attempted to un-register and re-register the function as a child to no avail:

    remove_action( ‘genesis_do_search_title’ );

    add_action( ‘child_genesis_do_search_title’ );
    function child_genesis_do_search_title() {

    $title = sprintf( ‘%s %s’, apply_filters( ‘genesis_search_title_text’, __( ‘Listing Results:’, ‘genesis’ ) ), get_search_query() );

    echo apply_filters( ‘genesis_search_title_output’, $title ) . “\n”;

    }

    HELP!

    Thank you

    • Bill Erickson says

      My guess is you’re unregistering the function in functions.php, which is too early. There’s two ways you can do this:

      1. In functions.php, write a function that filters ‘genesis_search_title_text’. Ex: https://gist.github.com/billerickson/32bf346b5e17d2d5ed47

      2. Create your own search.php file in your child theme, which will then be used instead of Genesis’ search.php. The search results will no longer have a title, so you will create a function in your search.php file to add the title you want.

      For your specific needs, #1 is best. But if you plan to make lots of customizations to the search results page, go with #2.

  5. Paul says

    Hi Bill.

    Common story here, I’ve been searching Google for hours looking for an answer, but have come up empty. I’m trying to re-position the ‘Search Results for:’ heading on the search results page. I know I need something like this…

    remove_action( ‘genesis_before_loop’, ‘XXX_XXX_XXX_XXX_XXX’, 15 );
    add_action( ‘genesis_before_content’, ‘XXX_XXX_XXX_XXX_XXX’, 15 );

    but for the life of me, I can’t figure out what to put where the X’s are; I’ve tried every combination of ‘genesis’ ‘search’ ‘description’ ‘title’ etc that I can think of.

    I’m using ‘WordPress 4.4’ and the Genesis child them ‘Focus Pro.’

    Any help would be much appreciated!

    (Thanx for this page, I now know what the ’15’ after the X’s means!)

    Thanx Bill!

    Paul

    • Bill Erickson says

      The code that powers that is in genesis/search.php: https://gist.github.com/billerickson/40f409bde3eb7370091e

      Create your own search.php file in your child theme. This will then be used instead of the Genesis one (WordPress first looks in the child theme for a specific file, then the parent theme). You can then place whatever function you like and attach it to whatever hook you like. Since the code is in search.php, it will only apply to search results.

      • Paul says

        Thank Bill! That worked perfectly!

        That was EXACTLY what I was looking for!

        Much, much, much appreciated!

        Paul ๐Ÿ™‚

  6. Paul Anderson says

    Hi Bill, Paul again.

    A many moons ago, I found this code of yours (which is actually what lead me here): https://www.billerickson.net/default-category-and-tag-titles

    I was wondering if there was a way to also display the NUMBER of posts in the category, so that if I went to the ‘toys’ category page it would display at the top of the page something like…

    There are 10 posts in category: toys

    I did quite an extensive search but wasn’t able to find much in the way of a solution for this. To be honest, I’m surprised this isn’t standard on WP or that StudioPress didn’t build it into Genesis โ€” showing the number of posts in a category gives a person a good idea of how many posts they may have to wade through to find what they’re looking for.

    The closet thing I found was this:

    $wp_query->found_posts

    which does display the number of posts, but it appears up in the top left corner.

    Paul ๐Ÿ™‚

    • Bill Erickson says

      I never use the customizer so I’m not sure. Hopefully someone else can respond with the answer, or you can try StudioPress support.

  7. Johnny C says

    Bill i know you are a busy man, if you have time, i have an issue you might can lead me in the right direction. I have added a walker function for the genesis menu.
    For some reason on genesis 2.2.7 it only displays the description above the title and the version before this it worked correct! I am assuming that some code changed in the genesis framework that does not work correct with this function.
    Here is the code i am using for the description!

    https://gist.github.com/billerickson/f1de0f5954ed64c69ef04e88fcd251c3

    Any insight on this would be great, i figure you would know better than anyone! Thanks John

  8. Johnny C says

  9. Johnny C says

    Hey Bill i got the style figured out.. ” li:hover a, li:hover .menu-description” Thanks man, keep up the great work!

    Thanks so much

Leave A Reply