Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
- <aside class="widget-area" role="complementary" aria-label="<?php esc_attr_e( 'Footer', 'twentynineteen' ); ?>">
- <?php
- $cats = get_the_category();
- $cat_name = $cats[0]->name;
- print_r($cat_name);
- if ( is_active_sidebar( 'sidebar-1' ) and
- (strcasecmp('category with no footer widgets', $cat_name) == 0)) {
- ?>
- <div class="widget-column footer-widget-1">
- <?php dynamic_sidebar( 'sidebar-1' ); ?>
- </div>
- <?php
- }
- ?>
- </aside><!-- .widget-area -->
- <?php endif; ?>
- function remove_footer_widget_area( $sidebars_widgets ) {
- $cats = get_the_category();
- $cat_name = $cats[0]->name;
- if( (strcasecmp('category with no footer widgets', $cat_name) == 0) ) {
- unset($sidebars_widgets['sidebar-1']);
- }
- return $sidebars_widgets;
- }
- see https://chrisblackwell.me/hide-widgets-specific-wordpress-pages/
- a few notes:
- — 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.
- — For historical reasons, `'sidebars'` here really means `'widget areas'`. WordPress is full of anachronisms like this.
- — Another anachronism is the function name `get_the_category()`, which gets an array of categories. So it really should be called `get_the_categories()`.
- — 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