My Wordpress theme is using some code in the "sidebar.php" file that tells it that some pages should always use the default sidebar. This was fine until I found that each and every custom taxonomy (example: "taxonomy-mountains.php") page is defaulting to this default sidebar.

I thought about catching this with is_taxonomy(), but that's deprecated and won't work. Any better programmers out there with an idea of how I could fix this now. Something like if(is_taxonomy('mountains')){} would've worked fine. Below code is an excerpt, if you think something is missing let me know.

//Default sidebar
$selected_sidebar_replacement = 'Sidebar Widgets';

//If is page or single
global $wp_query;
$post = $wp_query->get_queried_object();
$selected_sidebar_replacement = get_post_meta($post->ID, 'sbg_selected_sidebar_replacement', true);

//If default selected
if($selected_sidebar_replacement == '0' || $selected_sidebar_replacement == ''){
$selected_sidebar_replacement = 'Sidebar Widgets';

// Reset the global $the_post


The function that replaces is_taxonomy() is named taxonomy_exists(). Than there's also is_tax() and is_tag() that check if the query is for a taxonomy archive page.


$selected_sidebar_replacement == '0' || $selected_sidebar_replacement == '' won't work. You're not checking the type.

Better do it like this:

if ( ! $selected_sidebar_replacement OR emtpy( $selected_sidebar_replacement ) )
  • Thanks @kaiser, however I don't know how to use this to display for example the sidebar "gear" when I'm in the taxonomy "product-brand". Below doesn't work. if(is_tax( 'product-brand' )){ $selected_sidebar_replacement = 'Gear'; } – WouterB Mar 27 '12 at 15:00
  • See Edit (filler) – kaiser Mar 27 '12 at 15:47
  • You're talking in riddles... "you can't change the taxonomy on your custom taxonomy pages"? Change? How? What? btw: ↑ you've been checking against '0' which is a string. That shouldn't happen when selecting a string... – kaiser Mar 27 '12 at 16:29
  • TYPO:"The issue I'm having is that I can't change the SIDEBAR on my custom taxonomy pages." Yes I have been checking against '0', and while it isn't a string, it is working, and your suggestion isn't. I'll look in to that later, but first I really need to figure out how to display different sidebars when I'm on different custom taxonomies. – WouterB Mar 27 '12 at 16:43
  • @WouterB As you marked it as solution: What exactly was the solution? – kaiser Mar 28 '12 at 11:09

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.