Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi kunalnc17,

    Hope you’re well ??

    Unfortunately this is not possible with Custom Sidebars plugin.

    What you can do here is create child theme of your current theme, register new sidebar and then edit files with IF function to call one sidebar for logged in users and one for logged out.
    It would require some coding but it shouldn’t be to hard to accomplish.

    Cheers,
    Predrag

    Thread Starter Kunal

    (@kunalnc17)

    Oh but could you guide me through the process like i am not creating the child theme currently but could you tell me a piece of code and i could put that

    Hi kunalnc17,

    Editing parent theme wouldn’t be good way here as the changes will be overwritten by theme updates.

    Basically what you would need to do is first register new sidebar in functions.php, something like this should do the trick:

    register_sidebar( array(
        'name' => __( 'Custom Sidebar', 'theme-slug' ),
        'id' => 'custom-sidebar',
        'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
    	'after_widget'  => '</li>',
    	'before_title'  => '<h2 class="widgettitle">',
    	'after_title'   => '</h2>',
    ) );

    You can find more info about it here:
    https://codex.www.ads-software.com/Function_Reference/register_sidebar

    Now you will need to edit the templates for your pages and posts, for example page.php and in there find where sidebar is called, it should look similar to this:
    <?php get_sidebar(); ?>

    That’s the part where you need to add IF condition and call different sidebar for logged out users, it would look something like this:

    <?php
    if ( is_user_logged_in() ) {
    	get_sidebar();
    } else {
    	get_sidebar('custom-sidebar');
    }
    ?>

    Hope this helps to get you started ??

    Cheers,
    Predrag

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I want a different sidebar for logged in users’ is closed to new replies.