2

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 3

2

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.

0

What I understand is that you want to display a widget on specific pages, right? You could use a plugin for that: https://wordpress.org/plugins/widget-context/

2
  • Hi Remzi. Thanks for responding. Prefer not to use a Plugin. Especially from what I read that the widget plugin like Widget Logic possible security breach
    – Joe
    Oct 12, 2018 at 13:23
  • I understand, there are a lot of bad ones out there. I have used several widget plugins and this one is small and simple. You could look at the source code, it also open source: github.com/kasparsd/widget-context-wporg Oct 12, 2018 at 13:31
0

Figured it out with below code:

<ul class="row">

   <?php if ( is_page( 1111 )) : ?>
   <?php dynamic_sidebar('footer-sidebarprestige'); ?>
   <?php else :?>
   <?php dynamic_sidebar('footer-sidebar'); ?>
   <?php endif; ?>

  </ul>

Thank you Pim, you sent me on the right track to get my answer

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.