Blog

Sharing WordPress tips and tricks as I find them

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)

77 Comments

  1. Great idea, Bill. I’ve got an Evernote notebook for this same thing.

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

    • Great but can I change this “2010″ to something automatic.

      • 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]

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

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

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

  5. This saved my life today:

    unregister_sidebar(‘sidebar’);
    unregister_sidebar(‘sidebar-alt’);

    Thank you Bill.

    Love,
    Greg

  6. thanks, very useful stuff. I’ll add them to my snippets collection!

  7. Thanks for the “force layout” function, just allowed me to list employees along with the Genesis Grid Loop on a full width page:)

    http://www.studiopress.com/support/showthread.php?p=291897&posted=1#post291897

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

  9. thank you ……its working…..

  10. How can we add “href anchor link” to logo in any “genesis child theme”?

    Thanks,
    Kumar Sekhar

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

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

  12. Bill,
    Thanks for sharing all of these code snippets. Glad I finally found this page. This is why I love the Genesis community.
    Mark

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

  14. Where on earth do I paste these codes? I’m trying to remove the sidebar on my theme.

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

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

  16. Have got a lot of use out of this post! Thanks Bill…Cheers!

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

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

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

  20. Thanks for a great post Bill, I found this looking for something else but it has extended my Genesis knowledge. Thanks for sharing.

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

  22. Awesome awesome tips – thank you so much for sharing! Already put a few of these to use.. Nice last name too :) Thanks again!

  23. Thanks for sharing. I have a Sublime Text 2 package that includes Genesis snippets. You can use tab triggers to generate many of these snippets and others inside Sublime. I’m curious, what editor do you use?

    Sublime Text 2 Genesis Package on Git
    https://github.com/jtallant/Genesis

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

  24. Many thanks for posting these useful code snippets. Genesis is such a cool framework with great flexibility, like it.

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

  26. A great collection of snippets, will be using in my future projects. Your tutorials have been really helpful.
    Thanks

  27. Hi Bill,

    Thanks for being such an awesome resource!

    I’m pretty new to PHP and am having trouble removing the hyperlink from the post titles in my sidebar. As far as I can tell, what I would like to do is have a function that changes this:
    https://gist.github.com/anonymous/1255c42b4f3c16fcb0c5

    to this:
    https://gist.github.com/anonymous/c833ce76a1758af8736a

    Any help you could provide would be much appreciated!

    • Bill Erickson says:

      Are you using the Recent Posts widget? Unfortunately that’s not customizable, so you’ll need to either find a plugin that displays the posts the way you want, or create your own widget.

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

  28. Great list of useful snippets.

    I’ve forked your code for Displaying Description of Menu Items and made some changes using some code from Travis Smith. https://gist.github.com/braddalton/4971966

    What do you think Bill?

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

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

    • Brad Dalton says:

      If you added a custom function with a priority of 10 using genesis_after_header, what would happen?

      https://gist.github.com/braddalton/5468154

      And what would happen if you didn’t add a third parameter to the code?

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

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

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

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

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

  35. Awesome resource!! This will save a lot of time … thanks for sharing.

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

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

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

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

Join the Conversation

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