• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Code to automatically assign a custom sidebar to posts

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Code to automatically assign a custom sidebar to posts

This topic is: resolved

Tagged: custom sidebar, Sidebar

  • This topic has 5 replies, 4 voices, and was last updated 6 years, 1 month ago by frankie.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • September 12, 2016 at 7:13 am #193014
    georgewking
    Member

    Hi all,

    I use Genesis Simple Sidebars and I designed one sidebar per category. It works very well but I would like, rather than manually assign a side bar to each post, to automatically show the corresponding sidebar when the post is shown (all my posts has only one category).

    Any help would be appreciated 🙂

    thanks,
    George.

    September 13, 2016 at 8:23 pm #193127
    Christoph
    Member

    Hi George,

    Neil's tutorial should do the trick : https://wpbeaches.com/bulk-set-sidebar-categories-tags-simple-sidebars-installed-genesis/


    https://www.christophherr.com | Genesis Customizations | Buy me a coffee

    September 14, 2016 at 9:41 am #193157
    georgewking
    Member

    Hi Christoph,

    Yes it woks!
    I just had to add a switch to assign one sidebar to each category and now is working as I wanted.

    Many many thanks,
    George.

    January 25, 2017 at 4:54 am #199984
    frankie
    Member

    Hi
    I wonder if someone is able to check that I have set up this code correctly please as I am not confident working with php and the functions.php file?!
    We have a large site with multiple custom sidebars using Simple Sidebars. But now we need to change a sidebar for one category only but this category has about 300 posts so I don't want to go through changing these manually! The category has a slug of 'here-now-aircraft' and the sidebar we need to allocate is 'hn-aircraft'.

    Based on the code from the Sept 13 Post I created the following. Will this work so that it retains all the current sidebars, but allocates one specific sidebar to the category defined:

    ----------

    add_action( 'genesis_before_sidebar_widget_area', 'themeprefix_remove_sidebar' ); // starts the ball rolling

    function themeprefix_remove_sidebar() {
    if ( is_category( 'here-now-aircraft' ) ) { // set your connditionals here
    remove_action( 'genesis_sidebar', 'ss_do_sidebar' ); // removes Simple Sidebar
    remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); // removes Genesis Default sidebar
    add_action( 'genesis_sidebar', 'themeprefix_add_sidebar' ); // adds alternative sidebar in function below
    }
    }

    // Alternative Sidebar
    function themeprefix_add_sidebar() {
    dynamic_sidebar( 'hn-aircraft' ); // add in the ID of the sidebar you want to replace it with
    }

    ------

    Many thanks

    January 25, 2017 at 6:48 am #199993
    Victor Font
    Moderator

    Frankie, this thread has been marked as resolved. Instead of adding to it, open up a new thread.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    January 25, 2017 at 7:38 am #199999
    frankie
    Member

    Oops! Thanks Victor, will do.

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Code to automatically assign a custom sidebar to posts’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble