Hey guys am coding a wordpress theme from scratch ..I need to enable a side bar on the right side of my theme.
So in my functions.php
i have enabled some code like
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'The sidebar',
'id' => 'home_right_1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
In my sidebar.php
<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div><!-- #secondary -->
<?php endif; ?>
In the style.css
.widget-area {
float:right;
width:330px;
}
But when i run the code the sidebar isnt displaying.I just want to display the sidebar on the right side of my theme page.
Thanx in advance
I think you must use Name or ID of dynamic sidebar
<?php if ( is_active_sidebar( 'home_right_1' ) ) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'home_right_1' ); ?>
</div>
<?php endif; ?>
And use this function
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => __('Main sidebar', 'framewrok'),
'id' => 'home_right_1',
'description' => __('Default main sidebar.', 'framework'),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="widget-title"><h2>',
'after_title' => '</h2></div>'
));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.