Display shop banner only on first page not on subsequent

Solved5 replies3 participantsUpdated by Tony Rodriguez

  • Avatar: kikjou
    Martin
    Participant

    Hello,

    I would like the shop banner (above the product grid) to appear only on the first page of my product listing. On subsequent pages (pagination pages 2, 3, etc.), this banner should not be displayed.

    How can I configure this? Is there a theme option available, or do I need to modify code?

    Thank you for your help!

    Best regards,
    Martin

    5 Answers

    Avatar: Jack Richardson
    Jack Richardson
    Support staff

    Hello @Martin,

    You may consider implementing the following code snippet in your child theme/functions.php file to display the Static block (https://www.8theme.com/documentation/xstore/support/static-blocks/) in specific position on Product category page (as you main Shop page displays the product categories items):

    add_action('woocommerce_shop_loop', function() {
    	global $paged, $page;
        global $woocommerce_loop;
    
    	$banner_shortcode = false;
        $position_banner = 6; 
    
        if ( $paged <= 1 && is_product_category() ) {
        	if ( is_product_category('computer-pc') ) { // to display specific banner on specific category by slug
        		$position_banner = 3;
        		$banner_shortcode = '[block id="298"]'; 
        	}
        	if ( is_product_category('smart-gadgets') ) { // to display specific banner on specific category by slug
        		$position_banner = 2;
        		$banner_shortcode = '[block id="809"]'; 
        	}
            if ( $banner_shortcode && (($woocommerce_loop['loop'] / 2) == $position_banner) ) {
            	$classes = array('shop-loop-banner product'); // product class for grid layout 
            	if ( !wc_get_loop_prop( 'etheme_default_elementor_products_widget', false ) && function_exists('etheme_get_product_class') )
        			$classes[] = etheme_get_product_class( $woocommerce_loop['columns'] );
            	echo '<div class="'.implode(' ', $classes).'">';
    	        	echo do_shortcode($banner_shortcode);
    	        	echo '<span class="screen-reader-text">Shop banner</span>';
            	echo '</div>';
            }
        }
    }, 9999);

    Please, make any imlementations only via FTP as some errors may occur, so your wp-admin may be blocked if you make changes from Dashboard -> Appearance -> Edit Theme.

    Best Regards,
    Jack Richardson
    The 8Theme’s Team

    Avatar: kikjou
    Martin
    Participant

    Hi,

    I think there was a misunderstanding. That snippet that you have given me appears to insert a “tile” into the product loop (in the size of a product).

    This snippet does the trick: It simple removes the shop banner from all subsequent pages, i.e. prevents the hook from loading. As far as I can judge it works correct. Please, let me know, if you see any potential problem with it:

    /**
     * Pflanzkompass: Shop-Banner (Static Block 36388) nur auf Seite 1 der Shop-Seite.
     * Ab Seite 2 wird der Block gar nicht erst erzeugt.
     */
    add_filter( 'pre_do_shortcode_tag', 'pk_shop_banner_nur_seite_1', 10, 3 );
    function pk_shop_banner_nur_seite_1( $return, $tag, $attr ) {
    
    	// Nur der Static-Block-Shortcode mit der ID des Shop-Banners.
    	if ( 'block' !== $tag || ! isset( $attr['id'] ) || '36388' !== (string) $attr['id'] ) {
    		return $return;
    	}
    
    	// Nur auf der Shop-Seite ab Seite 2.
    	if ( is_shop() && is_paged() ) {
    		return '';
    	}
    
    	return $return;
    }

    At any rate, you very much for your answer , because “inserting a tile” would have been my next ticket.

    Kind regards
    Martin

    Avatar: Jack Richardson
    Jack Richardson
    Support staff

    Hello @Martin,

    We apologize for any misunderstanding. It appears that we have already provided a solution for your upcoming ticket. For this request, you could easily implement this solution using custom CSS as follows:

    .archive[class*=tax-product_] .category-description {
        display: none;
    }

    This will hide the description section on all product taxonomy archives. But if your solution works better, keep using yours.

    Best regards,
    Jack Richardson
    The 8Theme’s Team

    Avatar: kikjou
    Martin
    Participant

    Thanks for the support! My topic “Display shop banner only on first page not on subsequent” has been successfully resolved.

    Avatar: Tony Rodriguez
    Tony Rodriguez
    Support staff

    Dear Martin,

    Thanks for being part of our WordPress & WooCommerce community!

    We’re happy we could assist you. Your feedback truly matters — it helps us make XStore better, faster, and more reliable with every release.

    Together, we’re shaping a better WooCommerce experience for everyone.

    Topic closed.
    The 8Theme Team

The issue related to '‘Display shop banner only on first page not on subsequent’' has been successfully resolved, and the topic is now closed for further responses