Code Snippet – Genesis Framework – Move Primary Sidebar

So I haven’t blogged in FOREVER! but hopefully will be doing so more often. One thing I’ve been wanting to do is post code snippets that are helpful to me as I work on client projects, so here’s the first snippet:

remove_action( 'genesis_after_content', 'genesis_get_sidebar' );
add_action( 'genesis_before_content', 'genesis_get_sidebar' );

This code is for use with the Genesis Framework for WordPress. I’ve used it on many recent client projects and like it, but sometimes it can be hard to figure out how to do something simple –  in this case, I needed to move the primary sidebar div (#sidebar) above the content div (#content).  As I was searching, all the sites suggested I used some variation of this code:

add_action('genesis_before_content', 'genesis_do_sidebar');

That was obviously enough for some people, but here’s the problem with the above code: it doesn’t move the sidebar div, it just removes the default content of the sidebar div. By default in Genesis, the primary sidebar div is structurally after the content div – but I needed it to be loaded first.

If this was helpful to you, let me know in the comments!

Happy coding!

One comment on “Code Snippet – Genesis Framework – Move Primary Sidebar

  1. Lori says:

    Thanks for the post. I didn’t end up using this but he code works. Altering the load order of the sidebar would be particularly handy in some mobile implementations.

Leave a Reply

Your email address will not be published. Required fields are marked *