WebCraft Tools

  • News
  • WordPress
    • WordPress Basics
    • WordPress Advanced
    • WordPress Performance
    • WordPress Security
    • WordPress Commerce
    • WordPress Troubleshooting
    • WordPress Themes
  • SEO and Analytics
WebCraft Tools › WordPress Advanced › Set default layout for a Custom Post Type with Genesis

Set default layout for a Custom Post Type with Genesis

Last updated on April 19, 2017 by Editorial Staff

I have recently (yesterday) taken the plunge into building my websites with Genesis. I’m not exactly sure why I’ve been holding out. Most likely because I had built my own kind of framework and really like some specific things I had built into it. The problem is that I just don’t have time to work on all the other stuff that’s important for a good theme framework. So now I’m using Genesis and I couldn’t be happier. I still needed to solve a problem though so here it is.

I wanted my default layout to be CONTENT-SIDEBAR but I wanted a particular post types archives and single posts to be SIDEBAR-CONTENT. With the Genesis genesis-cpt-archives-settings custom post type support I can accomplish this for the archive pages but not for the single posts. This snippet solves that problem.

function wpnj_cpt_layout() {
    if( 'your_post_type' == get_post_type() ) {
        return 'sidebar-content';
    }
}
add_filter( 'genesis_site_layout', 'wpnj_cpt_layout' );

This code checks what custom post type you are viewing and applies this layout if it’s the one you’re looking for. Pretty simple.

Tweet1
Pin
Share2
3 Shares

Filed Under: WordPress Advanced

Comments

  1. Tom says

    August 11, 2013 at 5:33 pm

    One of the great things I’ve found about Genesis are the number of quality plug-ins that are available to do things without having to code for results. There’s certainly nothing wrong with adding code, but the plug-ins are an instant go-to solution and most offer easy what-if sampling and other options. You can also use them from site to site where you may be using different Genesis themes.

    For instance, you should be able to get the same results for your CPT using David Decker’s “Genesis Layout Extras” plugin, which offers a layout selection per CPT and adds layout options not offered by Genesis. Even though Genesis has up to 6 layouts, David’s plugin adds at least 3 additional layouts and adds 9 additional layouts if your theme supports alt-sidebars (secondary sidebars).

    Reply
    • Jim Proctor says

      January 23, 2016 at 6:20 pm

      I’ve used Genesis Layout Extras as well, but it hasn’t been updated recently and is incompatible with at least one of my other plugins (running WP 4.4.1). I would love to modify your code for it to check not for a certain post type, but to check whether the page is the home page, and if so to apply a certain layout…is this possible? I don’t want to redo the whole front-page.php format for my child theme; I just want a different layout for the home page, and Genesis Layout Extras did this for me fine…until it started messing with other plugins.

      Sure appreciate!

      Jim P.

      Reply
  2. Manning Stinson says

    August 24, 2013 at 10:17 pm

    You may want to also check out u-Design. Awesome framework. I am using Ninja Forms with the theme and have had know theme conflicts at all.

    http://themeforest.net/item/udesign-wordpress-theme/253220

    Reply
    • Manning Stinson says

      August 24, 2013 at 10:17 pm

      *** NO known!

      Reply
  3. Chris Ward says

    April 14, 2015 at 1:16 pm

    Thanks for this James, it solved exactly what I was looking for.

    Reply
  4. Jim Proctor says

    January 23, 2016 at 6:44 pm

    Ah, that was easy…thanks for the inspiration…

    if ( is_home() ) {
    return ‘sidebar-content-sidebar’;
    }

    Reply

Leave a Reply Cancel reply

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

Site Links

  • Contact Us
  • Disclosure Statement
  • Privacy Policy

About WebCraft.tools

WebCraft.tools is your free resource for building, maintaining, and improving your WordPress website. Whether you are building your first site or have been building them for years, WebCraft.tools aims to provide you with tips, tricks, tutorials, and reviews to take your WordPress site to the next level.

© 2017 - 2021 · WebCraft Tools · Built by the WP Ninjas, LLC