I registered a new footer widget with this code.
register_sidebar(array(
'name' => esc_html__( 'Footer Sidebarprestige', 'realtor' ),
'id' => 'footer-sidebarprestige',
'description' => esc_html__( 'Widgets in this area will be shown in Footer Area.', 'realtor' ),
'class'=>'',
'before_widget'=>'<li id="%1$s" class="col-md-3 col-sm-6 widget %2$s">',
'after_widget'=>'</li>',
'before_title' => '<h5>',
'after_title' => '</h5>'
));
I called it in my footer.php file like this:
<ul class="row">
<?php dynamic_sidebar('footer-sidebar'); ?>
</ul>
<ul class="row">
<?php dynamic_sidebar('footer-sidebarprestige'); ?>
</ul>
The ‘footer-sidebar’ is original widget and the ‘footer-sidebarprestige’ is the one I added. The way it is now if I add a widget to the widget area I added it shows up under the original one and I understand why.
What I am trying to do. Call the widget area that I added only for certain page ID’s. Basically, only on called page ID’s show newly created footer widget and not show the original widget area.
3 Answers
There are several ways you can achieve this:
A. Use CSS to hide and show widgets based on which page you are on. This is fine as a workaround, but it isn’t really solving your problem, especially if you have lots of pages/widgets.
B. Call a different widget area in your template file with conditional logic
<ul class="row">
<?php if(is_page('my-page')){
dynamic_sidebar('footer-sidebarprestige');
} ?>
</ul>
C. Use a plugin like Widget Logic to use conditional logic on the widgets themselves. You can then add a condition like is_page('my-page')
for displaying the widget, on a widget-per-widget basis.