Support » Themes and Templates » Widgets problem with Flat Bootstrap theme

  • I had a tough time trying to get the widgets working with the Flat Bootstrap theme.
    If I switched to another theme, the widgets worked just fine, but with this one, only the default widgets were shown, no matter the changes I did in the admin widgets section. Also, the “widgets customizer” just thrown a message that there were no widgets areas available.
    Finally, I discovered that if in the code I changed the widget areas names for the ids, it worked!
    Example (in sidebar.php)
    Instead of <?php if ( ! dynamic_sidebar( ‘Sidebar’ ) ) : ?>
    I need to put <?php if ( ! dynamic_sidebar( ‘sidebar-1’ ) ) : ?>
    no one else is facing this problem?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,
    The WordPress widgets are showing and customizer widgets both are working for me without touching any code section.
    SEE-> http://prntscr.com/9u2xdn
    You might have to reactivateFlat Bootstrap theme again using following Steps:
    1.Click on Appearance » Themes>> Activate other theme than Flat Bootstrap theme.
    2.Again,Click on Appearance » Themes>> Hover the Mouse over Active theme>> Click the “Theme Details” button.
    3.Click Next Arrow button on the top left side of theme until you find Flat Bootstrap theme. Click Delete button
    4.Go to Appearance » Themes>> Add New >>Upload Flat Bootstrap theme. Activate the theme.
    Now, check customizer section of theme again and widgets section to see if your issue is resolved by doing so.

    It’s really strange. I did what you suggest and the result is the same. It only works if I modify the code.
    The message I see in the customizer, instead of the widget areas is:
    “At this moment, there are no areas currently displayed in the widget preview. Browse the preview to a template that uses a widget area to access your widgets here.”

    I found it!
    It’s a problem with the internationalization (I’m using Spanish version).
    the register_sidebar function is using:
    ‘name’ => __( ‘Sidebar’, ‘flat-bootstrap’ )
    while the template pages are this way:
    if ( ! dynamic_sidebar( ‘Slidebar’ ) ) : ?>
    That results in names discrepancy.
    So if I apply interationalization in both places, it also works:
    if ( ! dynamic_sidebar( __( ‘Sidebar’, ‘flat-bootstrap’ ) ) ) : ?>
    This helps as a refference:
    https://codex.wordpress.org/Function_Reference/_2

    I just did a test that __( ‘Sidebar’, ‘flat-bootstrap’ ) returns “Barra lateral” (which is sidebar in Spanish). That’s why it’s not working.

    I also found that an easier way to solve the widgets problem in internationalized versions, instead of editing several files is to strip the internationalization out of the names in register_sidebar functions.

    Mine is now this way:

    function xsbf_widgets_init() {
    
    	// Put sidebar first as this is standard in almost all WordPress themes
    	register_sidebar( array(
    		'name'          => 'Sidebar',
    		'id'            => 'sidebar-1',
    		'description' 	=> __( 'Main sidebar (right or left)', 'flat-bootstrap' ),
    		'before_widget' => '<aside id="%1$s" class="widget clearfix %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h2 class="widget-title">',
    		'after_title'   => '</h2>',
    	) );
    
    	// Put footer next as most themes put them here. Default # columns is 3.
    	register_sidebar( array(
    		'name' 			=> 'Footer',
    		'id' 			=> 'sidebar-2',
    		'description' 	=> __( 'Optional site footer widgets. Add 1-4 widgets here to display in columns.', 'flat-bootstrap' ),
    		'before_widget' => '<aside id="%1$s" class="widget col-sm-4 clearfix %2$s">',
    		'after_widget' 	=> "</aside>",
    		'before_title' 	=> '<h2 class="widget-title">',
    		'after_title' 	=> '</h2>',
    	) );
    
    	// Page Top (After Header) Widget Area. Single column.
    	register_sidebar( array(
    		'name' 			=> 'Page Top',
    		'id' 			=> 'sidebar-3',
    		'description' 	=> __( 'Optional section after the header. This is a single column area that spans the full width of the page.', 'flat-bootstrap' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix"><div class="container">',
    		'before_title' 	=> '<h2 class="widget-title">',
    		'after_title' 	=> '</h2>',
    		'after_widget' 	=> '</div><!-- container --></aside>',
    	) );
    
    	// Page Bottom (Before Footer) Widget Area. Single Column.
    	register_sidebar( array(
    		'name' 			=> 'Page Bottom',
    		'id' 			=> 'sidebar-4',
    		'description' 	=> __( 'Optional section before the footer. This is a single column area that spans the full width of the page.', 'flat-bootstrap' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix"><div class="container">',
    		'before_title' 	=> '<h2 class="widget-title">',
    		'after_title' 	=> '</h2>',
    		'after_widget' 	=> '</div><!-- container --></aside>',
    	) );
    
    }

    @roccons2, you are so awesome for finding that and commenting on how to fix it!

    I definitely would like to leave the sidebar names translatable, so what I’ve done is update all the calls to load the sidebar to use its “id” instead of its “name”. So “sidebar-1”, “sidebar-2”, etc. I would love to change the id’s to something more meaningful, but then everyone would lose their widget settings. So I’m leaving them the way they are.

    This fix will be in the next release! (v1.7)

    I’m glad to know you found my comment useful!
    I think to achieve the behavior that you want it could be better adding internationalization to the calls, instead of using the id’s, as in the example:
    if ( ! dynamic_sidebar( __( ‘Sidebar’, ‘flat-bootstrap’ ) ) ) : ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Widgets problem with Flat Bootstrap theme’ is closed to new replies.