• 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

Custom Sidebar for the Homepage

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 › General Discussion › Custom Sidebar for the Homepage

This topic is: resolved

Tagged: custom sidebar, simple sidebars

  • This topic has 14 replies, 5 voices, and was last updated 8 years ago by Carlo.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • January 12, 2015 at 6:28 pm #137264
    Hashim
    Member

    Hi there,

    Thank you for taking the time and effort to read my support question!

    I'd like to have a custom sidebar for all my blog posts and another for my homepage.

    I already created the sidebars I need. But it's too much trouble to go through all the blog posts I've ever written and select the correct sidebar for it.

    So I thought I'd use the regular primary sidebar for all my blog posts and use a custom sidebar for my homepage. The only problem is I can't find my homepage in 'Pages' to select the correct sidebar.

    My question is, how can I have a sidebar for my homepage and a custom sidebar for all my blog posts without having to go through all my previous posts to select the custom sidebar? Or how can I appoint a custom sidebar for my homepage while I can't find my homepage (not a static page but the standard most recent blog posts page) in Pages to choose a custom sidebar for?

    Thank you in advance!

    Sincerely,

    Hashim

    http://aziemafatima.com
    January 13, 2015 at 2:56 am #137302
    Brad Dalton
    Participant

    Try this https://wordpress.org/support/topic/custom-widget-sidebar-on-homepage


    Tutorials for StudioPress Themes.

    January 13, 2015 at 5:41 pm #137368
    Hashim
    Member

    Hi Brad,

    Thank you for responding!

    I've checked out the plugin but it seems to be for widgets. Maybe I'm missing something here, because I don't understand how this plugin could solve my problem. If you would be so kind to provide a short explanation, I'll give your solution a go.

    Thank you in advance!

    Sincerely,

    Hashim

    January 14, 2015 at 3:51 am #137405
    Carlo
    Member

    Hi Hashim. Add the following code to your template front-page.php (i.e. after the <?php line):

    remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
    add_action( 'genesis_sidebar', 'YOUR_FUNCTION_HERE' );

    ...where YOUR_FUNCTION_HERE is the name of the function you have created that includes the call to genesis_widget_area.

    If you don't have a template front-page.php, create it and give it the following contents:

    <?php
    
    remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
    add_action( 'genesis_sidebar', 'YOUR_FUNCTION_HERE' );
    
    genesis();

    Hope that makes sense. If you need further clarification let me know.


    Comprehensive, easy to follow Genesis documentation

    January 14, 2015 at 6:34 pm #137497
    Hashim
    Member

    Hi Carlo,

    Thank you so much for participating! I'm really grateful for the time and effort you took to try to help me. Also to you, Brad. I know this is a community forum and you're not obliged to help me in any way whatsoever. But you still do in your own free time and that's just amazing!

    Carlo, I'm really good at copying and pasting code. :p Writing code is a bit too much for me at the moment. But that can chance because I'm a fast learner.

    I actually didn't create a function for a custom sidebar. (Or maybe I did without realizing.) I used the plugin Genesis Simple Sidebars. And now I know I forgot to mention that in my first message. Forgive me for the misunderstanding.

    What I actually want is a sidebar on my homepage, a custom sidebar on my about me page and a custom sidebar for my single posts. The problem with the plugin is that you have to select on per page/post basis which sidebar you want. But I'd like all my posts to have the same custom sidebar without going through all my posts and select the right sidebar. So I figured I'd leave the default primary sidebar for my single posts and create a custom sidebar for my homepage. But that's impossible with that plugin.

    Of course, it'd be better if I could create these three custom sidebars without the plugin so I can delete the plugin. But I don't know how to write the code to create these sidebars.

    I hope this gives you better understanding of my problem and my skills (or the lack of it). And I'm looking forward to your reply!

    Sincerely,

    Hashim

    January 15, 2015 at 9:44 am #137543
    Carlo
    Member

    Hi Hashim. This is a solution that is going to take a lot of code and one that I think others might need too, so I am going to put the tutorial on my site.

    I wrote a tutorial for a similar solution: http://carlomanf.id.au/local-global-sidebars/ but that's for if you want to seamlessly combine two widget areas in the one sidebar.

    Add yourself to my mailing list to be notified when the tutorial is ready.


    Comprehensive, easy to follow Genesis documentation

    January 15, 2015 at 1:16 pm #137587
    Ren Ventura
    Member

    Here's the code for it (goes in your functions.php WITHOUT the opening PHP tag). Just note that if your front page's template is widgetized, you'll need to modify it to output the home widget. Also, this removes the default primary sidebar when a page with a custom sidebar is displayed. You can easily reverse that if you'd like by removing the following code on lines 45, 57 and 69:

    // Remove the default/primary sidebar
    remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
    

    https://gist.github.com/EngageWP/955429f13705689bb35e


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    January 15, 2015 at 1:21 pm #137588
    Badlywired
    Member

    Hashim,

    If you aren't a coder these approaches are not for you, because they are code heavy.

    You can achieve what you want with one primary sidebar and then applying conditions so that you control what pages display what widgets. Like this

    Primary SideBar
    Widget A - show on home page only
    Widget B - show on about page only
    Widget C - show on all pages & posts except homepage & about page
    etc

    See what I mean? This way you just have to go through your widgets once, not all your posts.

    WordPress does allow you to apply logic of when widgets are displayed however there are at least two plugins that do
    - WidgetLogic https://wordpress.org/plugins/widget-logic/
    - JetPack https://wordpress.org/plugins/jetpack/ which has this as one of its many options

    Jetpack is easier to use for a non programmer, Widget logic requires you to understand WordPress conditional tags http://codex.wordpress.org/Conditional_Tags

    There may be more plugins like this out there, but these are the two I know that currently work


    My techy blog WordPress and stuff badlywired.com

    January 15, 2015 at 1:29 pm #137590
    Ren Ventura
    Member

    @Badlywired's suggestion is also a good call. The Widget Login plugin is one I use myself because it allows you to drop a simple conditional like the ones I used in the gist directly into a widget, i.e. is_page( 'about' ).


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    January 18, 2015 at 1:32 pm #137865
    Hashim
    Member

    Hi there,

    Thank you Carlo, Ren and Badlywired! I really appreciate your valuable contributions. It really brings back some joy in these dark times knowing that there are people like you willing to spend their time and energy to help others without expecting anything in return. Thank you very much!


    @CarloManf
    , Thank you for sharing that tutorial. And I'm very curious to your new tutorial which you'll share on your website. I'll add myself to your mailing list and hope to hear soon that you've finished so I can take a look. Thank you in advance!

    @RenVentura, A whole lot of code indeed, but nothing that looks too difficult to follow. Although I don't know any code, I still like to be challenged by facing new things to learn. And adjusting your code to my preferences and making it work helps me learn a lot. So I'll give it a try! Thank you!


    @Badlywired
    , You're absolutely right that it's a lot easier with plugins. And although I prefer to use as little plugins as possible, I'll definitely make use of WidgetLogic when I can't make it work with the code Ren provided. And I just checked out the link you provided about conditional tags. And now I understand the code in the functions.php file a lot better. So thank you for that!

    Time for me to try and fix this. And I'll be sure to keep you posted.

    Sincerely,

    Hashim

    January 18, 2015 at 2:01 pm #137873
    Badlywired
    Member

    Thank you for the thanks, it makes it worthwhile.


    My techy blog WordPress and stuff badlywired.com

    January 18, 2015 at 2:13 pm #137876
    Hashim
    Member

    It worked!

    Not only do I have all the sidebars shown exactly where I want them, I also learned how to do this thanks to all of your contributions.

    This is what I made of it eventually:

    //*Register custom sidebars
    genesis_register_sidebar( array(
    'id' => 'about-sidebar',
    'name' => __( 'About Page Sidebar' ),
    'description' => __( 'Sidebar for the About page.' ),
    ) );

    genesis_register_sidebar( array(
    'id' => 'single-post-sidebar',
    'name' => __( 'Single Posts Sidebar' ),
    'description' => __( 'Sidebar for single posts.' ),
    ) );

    //* Do custom sidebars
    add_action( 'genesis_sidebar', 'custom_sidebars_output', 0 );
    function custom_sidebars_output() {

    if ( is_page( 'about' ) ) {
    dynamic_sidebar( 'about-sidebar' );
    remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
    }

    if ( is_singular('post') ) {
    dynamic_sidebar( 'single-post-sidebar' );
    remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
    }

    }

    I never wrote code myself. So if you find any bad practices in this code please feel free to comment.

    Thank you once again all of you! And I wish you all the best for this year and all the years to follow!

    Sincerely,

    Hashim

    PS I don't know how to show the code I've used in such nice fields like you did, so I just copied and pasted it. Hope you don't mind.

    January 18, 2015 at 2:27 pm #137878
    Carlo
    Member

    Hi Hashim.

    Your code looks great for what you wanted to do and there are no bad practices.

    To show the code in a special field, you'll find a button labeled code above the forum reply field. Click on it before you paste your code and click on it again after you paste your code.

    Thank you for adding yourself to my mailing list. Although you figured it out I'll still add the tutorial.


    Comprehensive, easy to follow Genesis documentation

    January 19, 2015 at 4:23 pm #137989
    Ren Ventura
    Member

    Awesome to hear, Hashim. Thanks a lot of updating the thread and for showing your appreciation. It certainly does make volunteering worth it! 🙂


    Web & Software Developer & Blogger | RenVentura.com | Follow Me on Twitter @CLE_Ren

    March 12, 2015 at 4:32 am #144140
    Carlo
    Member

    I finally published the tutorial I promised I would:
    http://carlomanf.id.au/run-unique-sidebars/


    Comprehensive, easy to follow Genesis documentation

  • Author
    Posts
Viewing 15 posts - 1 through 15 (of 15 total)
  • The forum ‘General Discussion’ is closed to new topics and 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