Guest User

Untitled

a guest
Jan 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
  2.  
  3. <aside class="widget-area" role="complementary" aria-label="<?php esc_attr_e( 'Footer', 'twentynineteen' ); ?>">
  4. <?php
  5. $cats = get_the_category();
  6. $cat_name = $cats[0]->name;
  7. print_r($cat_name);
  8.  
  9. if ( is_active_sidebar( 'sidebar-1' ) and
  10. (strcasecmp('category with no footer widgets', $cat_name) == 0)) {
  11. ?>
  12. <div class="widget-column footer-widget-1">
  13. <?php dynamic_sidebar( 'sidebar-1' ); ?>
  14. </div>
  15. <?php
  16. }
  17. ?>
  18. </aside><!-- .widget-area -->
  19.  
  20. <?php endif; ?>
  21.  
  22. function remove_footer_widget_area( $sidebars_widgets ) {
  23. $cats = get_the_category();
  24. $cat_name = $cats[0]->name;
  25. if( (strcasecmp('category with no footer widgets', $cat_name) == 0) ) {
  26. unset($sidebars_widgets['sidebar-1']);
  27. }
  28. return $sidebars_widgets;
  29. }
  30.  
  31. see https://chrisblackwell.me/hide-widgets-specific-wordpress-pages/
  32. a few notes:
  33. — I'm assuming that the test as to whether to display the widgets depends on the category of the page, and the page is only in one category. Modify as needed.
  34. — For historical reasons, `'sidebars'` here really means `'widget areas'`. WordPress is full of anachronisms like this.
  35. — Another anachronism is the function name `get_the_category()`, which gets an array of categories. So it really should be called `get_the_categories()`.
  36. — The second approach copies-and-modifies a template file from the parent theme. But the template is small and unlikely to change.
Add Comment
Please, Sign In to add comment