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)

chat81 Comments

  1. blackpearl says

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

      • Bill Erickson says

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

    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.

    • Bill Erickson says

      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.

      • says

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

        • Bill Erickson says

          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. Dina says

    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!

    • Bill Erickson says

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

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

    • Bill Erickson says

      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. Cor van Noorloos says

    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

  6. says

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

    • Bill Erickson says

      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.

      • David Trees says

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

    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?

    • Bill Erickson says

      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. Dmitry says

    Hi. How do I exclude Homepage from showing breadcrumbs and still be able to show them on blog page?
    Thanks!

  9. says

    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.

    • Bill Erickson says

      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.

  10. says

    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

  11. says

    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!

    • Bill Erickson says

      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.

  12. says

    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

      • says

        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?

        • Bill Erickson says

          You’ll have to rebuild the Featured Posts widget. It does not offer the ability to customize the markup of listings.

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

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

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

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

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

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

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

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

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

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

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

Leave a Reply

If you'd like to include code in your post, please post it to http://gist.github.com and include a link.