• Resolved nikwolf

    (@nikwolf)


    I added my own widgets to display on blog pages/posts only, and not the front page or pages in general.

    I have woocommerce installed and because ‘is_single’ applies to single product pages, too, it is displaying there when I don’t want it to.

    I’m not great at php and I could google until I turn blue and waste hours trying to figure this out, I’m hoping posting in here will get a faster response than doing the above.

    I’m also using Genesis. Here is the code for the widget:

    add_action( 'genesis_before_footer', 'my_footer_widget2' );
    function my_footer_widget2() {
    	if ( is_home() || is_single())
    	genesis_widget_area ('my_footer_widget2', array(
            'before' => '<div class="footer_widget2">',
            'after' => '</div>',
    	) );
    }

    There are a total of three widgets that I need to fix so they display on single post pages, but NOT single product pages. This is in a custom_functions php file that is called by the main functions file for the theme I’m using.

    I tried using “not_is_product” after is_single, but that did not have any effect.

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Woocommerce creates a custom post type called Product for Products. To check if the single product is displaying, you can use the following conditional tag:

    is_singular('product')

    Here’s the updated code:

    add_action( 'genesis_before_footer', 'my_footer_widget2' );
    function my_footer_widget2() {
    	if ( is_home() || is_single()) {
               if (is_singular('product')) {return;}
    	   genesis_widget_area ('my_footer_widget2', array(
               'before' => '<div class="footer_widget2">',
               'after' => '</div>',
    	 ) );
             }
    }
    Thread Starter nikwolf

    (@nikwolf)

    Awesome!
    That did the trick, thank you so much!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display widget only on single posts, not single product page’ is closed to new replies.