I have a custom post type called "product" and I want to hide an specific widget only if the post type is "product" I was trying with something like this:

<?php function hidewidget() {
   $args = array(
   'name' => 'product'
   $output = 'objects';
   $post_types = get_post_types( $args, $output );
   return $post_types; } 
   $widhide = hidewidget(); 

      if ($widhide = 'product') {
      } else { 
    <div class="widgetclass"><?php dynamic_sidebar( 'filters' ); ?></div>
   <?php } ?>

The problem is the following: this function just return the name, I can't do anything with the name.

I need to call a function wich return a page with an specific kind of post.

It's possible in wordpress? any other solution to hide that div on the product detail page in woocommerce?

pd: I can't remove .widgetclass it needs to be there, I try with a plugin "widget display" to hide the widget but the .widgetclass div was still appearing obviously.


You could just check if it's the specific post_type..

if (is_singular( 'product' ) ) {
   //do nothing if it's a singular product page
  <div class="widgetclass"><?php dynamic_sidebar( 'filters' ); ?></div>

Make sure that the actual post type is just "product" and isn't namespaced.


I would use Widget Logic plugin and use the conditional inside the field:

! is_singular( 'product' )

This will show up on all but single product pages.

enter image description here


Add a conditional after the function name in the code which calls your widget.

if ( is_singular( 'product' ) ) 


if ( ! is_singular( 'product' ) ) 

Uses the ! NOT Logical operator with the is_singular conditional tag

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.