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.

Find this post useful? Donate through Paypal

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)

Tutorial

Receive New Posts by Email

Comments

  1. 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 &middot website &middot Terms &middot Privacy Policy
    ‘;
    return $creds;
    }

      1. 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]

  2. 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.

    1. 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:

      add_shortcode('post-title','post_title_shortcode');
      function post_title_shortcode($atts) {
      global $post;
      return get_the_title($post->ID);
      }

      Then you can use [post-title] as a shortcode anywhere in your site.

      1. 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!!!!!!!!!!!!!!!!

        1. 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);
          }

  3. 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!

    1. 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;}

  4. 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);

    1. 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.

  5. 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

        1. 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.

  6. 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!!

    1. 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_crumb filter.

    1. 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.

      1. So does that mean that adding these codes is down… Via… ;! … Only FTP into your sites theme folder?

        OK you guessed it, I’m an ultra newbie… It’s out now LoL

        Are there any videos that are of a standard you would recommend Bill?

        We all got to start somewhere with Genesis. Oh that’s right Genesis means beginning. Thanks for any ultra newbie tips or video suggestions.

        I’ve seen quite a few on the studio press site.

  7. 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?

    1. 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.

  8. 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.

    1. 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.

  9. 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

  10. 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!

    1. I use Coda, but I don’t have any built-in snippets. I work across multiple computers (a desktop and two laptops) so keeping code snippets in the program in sync is a nightmare. That’s why I set up code snippets on my site. I just leave that tab open in my browser, and when I need something I search that page for it.

      1. Hi Bill,

        Is this still your workflow with regards to snippets, and are you still using Coda? If not, would you mind sharing your current environment/workflow?

  11. Bill,
    Your articles are Extremely Helpful. You are THE MAN!! I just wanted to remove both footer AND markup, and voila, here it is!
    Thanks again,
    Dave

      1. Thanks for the tips. Actually it’s the Featured Posts widget, and since it’s the only place that displays posts on the site, I was hoping I could change the way ALL post titles are displayed – which I was then hoping would carry over to the Featured Posts widget that uses them. Is something like this possible?

          1. I am trying to unlink my post titles and can not seem to find a solution. Any help would be greatly appreciated. I also appreciate all the great advice I have received from your endless contributions.

          2. Add this to your functions.php file:

            add_filter( 'genesis_link_post_title', '__return_false' );

  12. 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.

  13. 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

    1. 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 );

      1. 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.

  14. 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

    1. 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.

  15. 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.

  16. 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?

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

  17. 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

  18. 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?

    1. 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.

  19. 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.

    1. Every page template in a Genesis child theme should end with genesis(); No matter how much custom code you’re adding to it, you should still be using Genesis.

      Here’s a landing page template that Jared and I use as a base when creating landing pages ( https://gist.github.com/billerickson/ff8d02cfeec041b3af6b ). It removes pretty much all the features of Genesis. Comment out the parts you want to keep.

      Here’s an example of how you’d unhook the main content area and replace it with your own ( https://gist.github.com/billerickson/1ae22572f2a8c56cb4aa ).

  20. 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.

    1. 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 = '';

  21. 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!

      1. Given the code provided in Genesis child theme function.php files (e.g., link in Chris Field post above), and your ‘Setup the child theme’ snippet, what would code added to Genesis child theme functions.php by developers look like?

        Many thanks

        1. If you are using a theme setup function, you would but all your add_action, add_filter, remove_action and remove_filter’s inside the setup function, and then place the actual functions after it. Like this: https://github.com/billerickson/BE-Genesis-Child/blob/master/functions.php

          If you are not using a theme setup function (you are doing the include_once() at the top), you can just drop the function and its add_action, add_filter… anywhere in the functions.php file. See all the StudioPress child themes as an example

  22. 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

    1. 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.

  23. 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

    1. 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.

  24. 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 🙂

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

  25. 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

  26. 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

Leave a comment