Create a child theme (if you haven’t already) and register two sidebars:
function wpse_151695_register_sidebars() {
register_sidebar(
array(
'name' => 'News',
'id' => 'sidebar-news',
)
);
register_sidebar(
array(
'name' => 'Blog',
'id' => 'sidebar-blog',
)
);
}
add_action( 'widgets_init', 'wpse_151695_register_sidebars' );
Then in your sidebar.php
:
if ( is_singular() ) {
// For single posts, show the sidebar relevant to the category it's assigned to.
if ( has_category( 'news' ) )
dynamic_sidebar( 'news' );
elseif ( has_category( 'blog' ) )
dynamic_sidebar( 'blog' );
} elseif ( is_category() ) {
if ( is_category( 'news' ) )
dynamic_sidebar( 'news' );
elseif ( is_category( 'blog' ) )
dynamic_sidebar( 'blog' );
}
Related Posts:
- Which banner plugin is this? [closed]
- List all sidebar names?
- How To Determine If A Filter Is Called In A Sidebar/Widget Context?
- Adding a widget programmatically
- Show missing Sidebar from Gutenberg admin area
- Override dynamic_sidebar() in plugin?
- Sidebar Generator issue [closed]
- Layout shop page: resize images and columns
- Flickr plugin that will display photos from multiple group pools? [closed]
- Way to hook into a sidebar call to replace it with a custom sidebar
- I need some direction on how to have a sidebar based on meta rather than page
- Multisite Widget/Content
- How to show my sidebar in specific page only?
- Missing argument 3 for wp_register_sidebar_widget()
- (WooCommerce) Remove Sidebar only on Single-Product page
- Custom random quote widget breaks when used in multiple sidebars
- How to display custom sidebar in wordpress 5.5.2
- Displaying Custom Sidebar Without Modifying Theme’s Core File?
- How to use my menu PHP code as sidebar?
- Best practice for including plugin output in a template without using shortcode?
- Widget’s container?
- How do I add the same contact form to multiple wordpress sites and capture the response in one place or database?
- How to Use the Filter “sidebar_login_widget_form_args”
- Woocommerce product info in a sidebar?
- Add Stack Exchange Recent Questions to a wordpress sidebar?
- Need to setup grid like thumbnail of recent posts on sidebar
- Widget content turns up before title
- Displaying number of drafts in Posts section of admin sidebar [closed]
- Listing all sidebars
- Mobile Menu and Mobile Sidebar missing
- Co-author plus: list of posts by authors in the sidebar
- How can I remove this sidebar from my Search Results page?
- Programmatically retrieve the sidebar/s classes
- Cannot access variables within a widget
- twitter widget loads properly in all themes except my own theme?
- Template from scratch: Sidebars not showing widget
- What method should I use for a sidebar widget that reads latest posts?
- Can’t edit Contact Us form on front page
- Is it possible to control content on different pages by checkboxing wich content is shown where on a wordpress theme page?
- Trying to Make a Sidebar/Tab on Specific Posts
- Pass user role to javascript code inside body
- A plugin that downloads other plugins
- Php page with filters for custom fields
- How to be escape Variables and options when echo?
- (WordPress 5.8.3) Function.php or a plugin for better performance? [duplicate]
- Basic question about accessing scripts in my plugin
- Gutenberg Blocks – Cannot retrieve block saved attributes in edit post
- plugins not working in custom theme
- How to use template_include hook with form submission?
- Adding Plugin Assets to Header
- Release the plugin in the WordPress repository where redux is used
- How to Define Multiple List Tables in a Single Submenu
- Add item to the woocommerce dashboard menu from a plugin
- Can the uniqueness of the plugin file/plugin slug and version number be trusted?
- Add type to enqueued script inside plugin
- Dokan Marketplace store link in single product page
- How can I redirect some pages to new subdomain? [closed]
- Automatically download, install and activate plugins that my plugin depends, how?
- Integrating boxtal PHP library into a custom WordPress Plugin
- wp-mail attachment is not sent for no reason?
- Translations for my plugin don’t show up
- Changing menu order of a specific plugin in dashboard
- Error in pdf generating plugin using FPDF
- syntax error, unexpected ‘while’ (t_while) please help :)
- How to create WordPress custom end point with multiple parameters?
- Plugin has added weird data in wp_options, set to autoload
- Different custom templates for product category [closed]
- Text change in Advanced Customs Fields [closed]
- How to remove bulk actions from custom post type
- After updating the WordPress getting a syntax error in the console
- Images under 1MB are not being compressed
- How to check wp_options’s rewrite_rules if current and existing are the same before flush the rules?
- What is the easiest way to rename a plugin (and also avoid plugin updates)
- Setting Email locale before retrieving gettext translations
- Changes not visible when not logged in
- Display linked articles at the bottom of post (like related posts)
- Simulating a wp page – wp page load sequence
- register_activation_hook() not working as expected
- How to redirect to same page after form submission
- Any idea how to get something like this to work? [closed]
- WordPress Ajax code is not Working
- Is there a maximum length to a WordPress Page?
- Skewed / slanted button within elementor [closed]
- WP.org acceptable iframe alternative
- I changed .live() to .on() but change is not reflected on the server
- How to find out whether a plugin is used in pages or posts?
- WooCommerce – set session with new cart item meta when updating cart item quantity [closed]
- Trying to add a page template for my custom post type from a plugin, but it will not display in the template dropdown unless file is in theme
- flush_rewrite_rules() not working with update_option_{$option}
- How to get the particular product quantity in orders in Woocommerce [closed]
- plugin dev – minimum base css specificity?
- Using WordPress to build membership Page
- How to generate an all in one WordPress New content, plugin and theme update report on a website? [closed]
- Tutor LMS problem with Paid Memberships Pro [closed]
- Is there a plugin for WordPress for creating ‘Accounts’ where all users who belong to that Account can only see Account data? [closed]
- A server-side hook failed when committing plugin code to SVN
- Custom shortcode for displaying user based on a role parameter
- Help with comments.php
- How to execute plugin and theme updates from a web hook / endpoint?
- WordPress Plugin Insert Html Code with Shortcode