Join my tribe!

Sign up to learn how to keep your skills up to date on the tech that matters most and confidently sell your skills to a growing customer base.
I will never spam you. You can unsubscribe at any time.

Reader Interactions

Comments

    • Carrie, Travis,

      Thank you both for helping. I know using Simple Sidebars and CPT archives added some complexity. I had tried using is_post_type_archive, which I thought was right, but I was missing the genesis_widget_area code – which solved the problem.

      Thanks a bunch!!!

      Lucas

    • Thanks, Travis! I was using dynamic_sidebar() based off some code I’d pulled off a Genesis Child Theme. When/why is it preferable to use genesis_widget_area()? Appreciate the info!

    • Just apply full width content layout to the archive. Add this near the top of your template page:

      /** Force full width layout */
      add_filter( ‘genesis_pre_get_option_site_layout’, ‘__genesis_return_full_width_content’ );

  1. This was great! I used the code but the new sidebar is showing below the primary sidebar. How do I omit the primary sidebar and just use the new one? Thank you!

  2. Hi Carrie… thanks for this post – saved me from using one more add-on than I needed to (was using widget logic before to determine what was displayed in a single sidebar depending on the page… it was a nightmare to maintain!) This should be much easier 🙂

  3. Hi Carrie! Great post. I’ve been looking for this for a while. I have a question though. Is there a set of guidelines on when to use an archive page (archive-$customCPT.php) vs. a template page (say template-$customCPT.php). Why didn’t you want to create a custom post template in the first place? I’m curious because I’m going to start coding a website and would like to know what’s the best approach. Thanks!

    • Hi there,
      It really just depends on your objective. If you use a template-$whatever.php, you’ll need to create an actual post or page and set it to use that template.

      On the other hand, if you use archive-$whatever.php, it will automatically be applied to that archive page (no “page” creation necessary). I know the terminology sounds kind of confusion. This codex page is terrible, but it might shed some light for you -> http://codex.wordpress.org/Template_Hierarchy.

      In the end, either way is appropriate, it just depends what you’re wanting to accomplish.

      Carrie

  4. Hi Carrie,

    Thanks for the great tutorial. I was just wondering if you’ll be posting the other tutorial you teased at the end – about how to use WP Type and Views to pull custom fields into the sidebar – anytime soon?

    • Hi Ben,
      I’m clearly running behind. 🙂 I still intend to post it, just haven’t had a chance to write it yet. You might check over at SureFireWebServices.com – Jonathan, who runs the site, is a big T&V user. Maybe he has something helpful in the mean time!

      Cheers,
      Carrie

    • This is what I’ve tried to apply a sidebar by author.

      //Add Custom Sidebar to Posts by Author
      add_action(‘get_header’,’cd_change_genesis_sidebar’);
      function cd_change_genesis_sidebar() {
      if ( is_single()) {
      global $post;
      $author_id=$post->post_author;
      if ($author_id == ‘Author’); {
      remove_action( ‘genesis_sidebar’, ‘ss_do_sidebar’ );
      add_action( ‘genesis_sidebar’, ‘cd_do_sidebar’ );
      } }
      }

      //Function to output my custom sidebar
      function cd_do_sidebar() {
      dynamic_sidebar( ‘Author’ );

      }

      Not quite there. It’s applying the same sidebar to all posts. Any ideas?

  5. Carrie, once again one of your tutorials saved me hours of ridiculousness. My client love the Metro Pro theme but wants a different sidebar on the front page than the rest of the site. I was feeling like a plugin would be overkill in this situation, so I used your code on the front-page.php file (except, of course the “register sidebar”). The only thing I did differently was remove: [code]if ( is_singular(‘jobs’)) { // Check if we’re on a single post for my CPT called “jobs”[/code] because I’m not looking for a CPT in this case. Worked beautifully. Again, thanks so much – please, Code Goddess, keep it up!!!

  6. Hi Carrie, Great post. This is exactly what i need. I too am using Types & Views, but I am not using Genesis, I am creating my own theme from scratch (based on the _s theme) and am not proficient in PHP at all. Do you know how i would modify this code in order that it would work in my theme?

    add_action(‘get_header’,’cd_change_genesis_sidebar’);
    function cd_change_genesis_sidebar() {
    if ( is_singular(‘jobs’)) { // Check if we’re on a single post for my CPT called “jobs”
    remove_action( ‘genesis_sidebar’, ‘genesis_do_sidebar’ ); //remove the default genesis sidebar
    add_action( ‘genesis_sidebar’, ‘cd_do_sidebar’ ); //add an action hook to call the function for my custom sidebar
    }
    }

    //Function to output my custom sidebar
    function cd_do_sidebar() {
    dynamic_sidebar( ‘job-single-sidebar’ );
    }

    • Hi,
      The only thing Genesis-specific about that code is ‘genesis_sidebar’ and ‘genesis_do_sidebar’. Genesis child themes don’t use sidebar.php (it pulls from the parent framework), so I’m not sure what best practice would be when it comes to underscores. You can likely just edit sidebar.php directly to display content conditionally.

      I’d skip this tut and look for better examples of conditional or custom sidebars. 🙂

      Carrie

      • Ah OK. I’ll see if I can decipher that 🙂 I am using the Custom Sidebars plugin which si great for indivdual pages, but not for entire post types. I’m hoping to find a solution that means i don’t have to create a custom template for each post type. I’ll keep searching 🙂

  7. Carrie:

    I’m running on Genesis and the Dynamik Website Builder (DWB) child theme. I have a CPT called Vignettes (the singular name is “vignette”) and I’ve created a Vignette Sidebar (id = vignettes-sidebar) using Genesis Easy Sidebars.

    I want to apply my new sidebar to my CPT and I’ve added the following code (from your post) to my DWB Custom Functions metabox, but it’s not working. Let me know if you see anything wrong.

    /* CHANGE SIDEBAR FOR VIGNETTE CPT using code by Carrie Dils */

    add_action(‘get_header’,’cd_change_genesis_sidebar’);
    function cd_change_genesis_sidebar() {
    if ( is_singular(‘vignette’)) { // Check if we’re on a single post for my CPT called “Vignette”
    remove_action( ‘genesis_sidebar’, ‘genesis_do_sidebar’ ); //remove the default genesis sidebar
    add_action( ‘genesis_sidebar’, ‘cd_do_sidebar’ ); //add an action hook to call the function for my custom sidebar
    }
    }

    //Function to output my custom sidebar
    function cd_do_sidebar() {
    dynamic_sidebar( ‘vignettes-sidebar’ );
    }

    • Please ignore my request above. I just realized that it’s working. But what I really want to make happen is to add my new Vignettes Sidebar to my Vignette CPT “Archives” … do you know of any code that will make this happen? Perhaps a modification of the above code so that it is the archive sidebars that are switched out?

      • I tried the following based on comment by Travis Smith (above), but it caused both admin and my website to crash, so I had to remove it from Custom Functions via FTP:

        /* CHANGE SIDEBAR FOR VIGNETTE CPT ARCHIVE using code by Carrie Dils */

        add_action(‘get_header’,’cd_change_genesis_sidebar’);
        function cd_change_genesis_sidebar() {
        if ( is_post_type_archive( ‘vignette’ )) { // Check if we’re on a single post for my CPT called “Vignette”
        remove_action( ‘genesis_sidebar’, ‘genesis_do_sidebar’ ); //remove the default genesis sidebar
        add_action( ‘genesis_sidebar’, ‘cd_do_sidebar’ ); //add an action hook to call the function for my custom sidebar
        }
        }

        //Function to output my custom sidebar
        function cd_do_sidebar() {
        dynamic_sidebar( ‘vignettes-sidebar’ );
        }

        • Hi Lang,

          Check out the comments from this post. Sidebars created by the Genesis Simple Sidebars plugin are created/removed with a different function that regular Genesis sidebars. The syntax change there should do the trick for you.

          Cheers,
          Carrie

        • Hi Carrie, you should put a disclaimer in this post about using Genesis extender and checking the box Custom Functions Effect Admin. I checked this as I was following your how-to, but didn’t realize how easily it could bring the website down. I put some bad php code into custom functions, and then was unable to log into WordPress to correct it. I think it’s better to leave this setting in extender unchecked, especially when you are in development and constantly updating the custom functions in the Extender UI. Anyway, thought I would share this with you. Otherwise, this post was extremely helpful to me. I appreciate such a thorough how-to on the subject of sidebars, since I am new to Genesis and Extender both. The comments on this post are also amazing. So much to learn, thanks!

  8. Hey Carrie,

    I’m using simple sidebars and am having trouble removing the default sidebar. I’ve tried:
    remove_action( ‘genesis_sidebar’, ‘ss_do_sidebar’ );
    remove_action( ‘genesis_sidebar’, ‘genesis_do_sidebar’ );
    but neither seems to work. Do you know if this has changed since 2.0?

    Thanks!

  9. Hi Carrie!

    Hoping you could help out. Myself and another Genesis user have asked the same question in the Genesis forum, however it looks like we are both stumped. How do we target the css for each custom sidebar created. In example we have a custom sidebar for “services” how could we target just that sidebar to say add a border?

    I did use firebug, but the css is targeting the primary sidebar: .sidebar.sidebar-primary.widget-area.

    Obviously we could create a rule manually that only targets the css with the above code for specific pages, but then every time we add a page that has that sidebar we would have to add to the rule, too much work, for what seems to have an easier solution. As the ID of the custom sidebar is NOT for css, is there a way to add a custom css class to each sidebar created?

    If you could lend a hand that would be awesome!

    Thanks
    Doug

  10. For any of you who have Genesis Simple Sidebars installed and are trying to switch sidebars on a CPT archive, or if you have WooCommerce installed, you should know that each of these plugins adds their own action to add a different default sidebar.

    So here’s some sample code to remove the default sidebar with either/both of these installed:

    remove_action( ‘genesis_sidebar’, ‘genesis_do_sidebar’); // remove the default genesis sidebar
    remove_action( ‘genesis_sidebar’, ‘gencwooc_ss_do_sidebar’ ); // remove the woocommerce sidebar
    remove_action( ‘genesis_sidebar’, ‘ss_do_sidebar’ ); // remove the default sidebar added by genesis simple sidebar

    Here’s a more full code sample, assigning two sidebars in different places on the site and removing all of the other ones from those places:
    https://gist.github.com/redblueconcepts/569876a43c034bd67852

  11. I am registering multiple sidebars and got errors because the name spaces were already taken. I changed these to something different and the code was accepted and the error report went away.

    Is there anything else I need to know if registering multiple sidebars as code in functions.php?

    Also, I might create the code in a new custom plugin rather than dropping it in functions.php. It is getting bloated.

    • Hey Darren,

      Yeah, when creating custom function, ID’s, etc, it’s good to preface them with your theme or plugin text domain to avoid conflict with anything else that might be using a similar name.

      For example, if my theme text domain is “utility-pro” then I could register a sidebar id as “utility-pro-cpt-sidebar”.

      Regarding the custom plugin vs functions.php, check out this article. 🙂

      Cheers,
      Carrie

  12. This site has become a Team Member over the last few days for me. I cant thank you enough for the information. Really great articles!!!

Trackbacks

Leave a Reply