1 – Currently the ‘Sidebar Pages’ or ‘Sidebar Blog’ if selected, are displayed in addition to and above the ‘Displayed Everywhere’ sidebar. Is this the correct functioning? I would expect ‘Sidebar Pages’ to override the ‘Displayed Everywhere’ sidebar….? Is this possible?
2 – I have created a sidebar called ‘Archive Sidebar’ I would like to show this sidebar for category archives rather than the ‘Displayed Everywhere’ sidebar
Could you please provide code snippet (in I presume sidebar.php) to make this change.
Thank you for your help!
Hello ttem!
1. You would need to empty the “Display Everywhere” sidebar in order to hide it from certain pages, because, it displays everywhere.
2. Yes, the trick is in sidebar.php, open that file an add this code around line 69 (see image):
if (is_archive()) {
dynamic_sidebar('archive-sidebar');
$default_sidebar = false;
}
Best regards,
Josue
Mil Gracias Josue!
Ok so to assign a sidebar to a specific category, I would add the category slug in the () like this:
if (is_archive(restaurants)) {
dynamic_sidebar(‘Restaurants Sidebar’);
$default_sidebar = false;
}
This should work?
Will if (is_archive()) also work for custom post type archive?
Hi!
No, is_archive() does not accept arguments, what you could use is is_category() to filter by a specific category (ex: ‘restaurants’).
Puedes hablar Español conmigo si prefieres.
Regards,
Josue