I'm implementing some widget area inside my custom theme. I've noticed that the added widgets are not display where I want, It will appear a blank area, also if I create a custom sidebar template for that. Is possible to check if there are widgets active for the theme and how? How I can fix the problem I'm facing?Here is the code I'm using:
functions.php
function contact_widget()
{
register_sidebar(
array(
'name' => __('Contact'),
'id' => 'contact-info',
'description' => __('Contact info'),
'before_widget' => '<div class="col-sm-12 col-md-6 col-lg-6 contact-widget>',
'after_widget' => '</div>',
'before_title' => '<h1>',
'after_title' => '</h1>',
)
);
}
add_action( 'widgets_init', 'contact_widget' );
function social_widget()
{
register_sidebar(
array(
'name' => __('Social'),
'id' => 'social-links',
'description' => __('Link social'),
'before_widget' => '<div class="col-sm-12 col-md-6 col-lg-6 text-center>',
'after_widget' => '</div>',
'before_title' => '<h1>',
'after_title' => '</h1>',
)
);
}
add_action( 'widgets_init', 'social_widget' );
Inside the customizer it will appear only the first widget I've registered but not the second. In the part of the theme where I want to display them will not appear nothing instead. Yhis is the relative code.
<?php if( function_exists('register_sidebar') ): ?>
<div class="jumbotron jumbotron-fluid services-action">
<div class="container">
<div class="row">
<?php if( is_active_sidebar('contact-info') ): ?>
<?php get_sidebar('contact-info'); ?>
<?php endif; ?>
<?php if( is_active_sidebar('social-links') ): ?>
<?php get_sidebar('social-links'); ?>
<?php endif; ?>
</div>
</div>
</div>
<?php endif; ?>
I want that this part is showed only if the widgets are active.
The two templates for the sidebar will give a deprecation error if I don't create also the sidebar.php
file. They only contain for now this line of code:
// sidebar-social.php
<?php dynamic_sidebar('social-info'); ?>
// sidebar-contact.php
<?php dynamic_sidebar('contact-info'); ?>
// sidebar.php
<?php get_sidebar(); ?>
```
Since the needed div classes are declared inside the registration of the sidebars I've not implemented nothing as html markup inside the templates files. If is possibile I will prefere to implement the div columns inside the sidebar template files instead using the `before_widget` and `after_widget`.
Any help will be appreciated.