• Resolved dianat

    (@dianat)


    I’m adding new sidebars to the front page. I have my sidebars registered, with separate sidebar files being called into a front-page template. Everything works as expected except…

    I’m getting a .left-sidebar style applied that I can’t account for, which limits the width to 21%-ish where I want 100%.

    Now, I could CSS my way out of this, but maybe there’s a way to create these sidebars that doesn’t pull .left-sidebar. Any ideas? Here’s an example of one. Pretty standard.

    In functions.php:

    $sidebars = array('Front Top');
    foreach ($sidebars as $sidebar) {
    	register_sidebar( array(
    		'name'          => __( 'Front Top', 'storefront' ),
    		'id'            => 'front-top',
    		'description'   => '',
    		'before_widget' => '<aside id="location" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h3 class="widget-title">',
    		'after_title'   => '</h3>',
    	) );
    }

    In sidebar-top-bar:

    if ( ! is_active_sidebar( 'Front Top' ) ) {
    	return;
    }
    ?>
    
    <div id="front-top" class="widget-area" role="complementary">
    	<?php dynamic_sidebar( 'front-top' ); ?>
    </div><!-- #front-top -->

    In front-page

    <?php get_sidebar('Front Top'); ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • That class comes from the main layout setting. You’ll need to filter the body class to remove it.

    Thanks

    Thread Starter dianat

    (@dianat)

    Thanks, James. I’ve got:

    add_filter('body_class', 'remove_a_body_class', 20, 2);
    function remove_a_body_class($wp_classes) {
    if( is_page_template('page.php') ) :
          foreach($wp_classes as $key => $value) {
          if ($value == 'left-sidebar') unset($wp_classes[$key]);
          }
    endif;
    return $wp_classes;
    }

    left-sidebar still shows up as a body class though. Not sure why.

    The code you pasted will only work on single pages due to is_page_template('page.php').

    That might be the issue?

    Thread Starter dianat

    (@dianat)

    Yes, that’s the issue. Thanks for your help.

    Just came across your post…

    I am having a problem with replacing the main sidebar on the dedicated blog page to a specific blog sidebar. I have managed to register the new sidebar in the widget area but cant seem to work which template the blog is using so I can call the action.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add new sidebars to home page’ is closed to new replies.