PriceCheaperton
PriceCheaperton

Reputation: 5349

Adding an image page banner to shop page

I am using WordPress 4.9.6.

I have set the shop page to be the home-page.

How do I add a page banner to the shop page. I would like to add it just above the breadcrumb trail.

I have tried adding this to the following page archive-product.php

if (is_shop()) {
        $args = array('taxonomy' => 'product_cat');
        $product_categories = get_categories( $args  );
        $term_id = $product_categories[0]->term_id;  
        $content = get_term_meta($term_id, 'cat_meta');
        if(isset($content[0]['cat_header'])){
            echo do_shortcode($content[0]['cat_header']);
        }
}

Unfortunately, not able to add any image to the page.

Upvotes: 1

Views: 2349

Answers (2)

dipmala
dipmala

Reputation: 2011

You can achieve using 2 methods.

1) Add your static image directly at the beginning of archive-product.php echo "<img src='{YOUR_IMAGE_PATH}'>";

2) Add filter in your theme's functions.php file.

 add_action ('woocommerce_archive_description' , 'shop_banner',99);
 function shop_banner() {
   echo  '<img src="{YOUR_IMAGE_PATH}" >';
  }

Upvotes: 2

Syntax_Error
Syntax_Error

Reputation: 817

I'm not so sure if I understand exactly what you want. But this is what I understand so far.

If you want to display an Static image banner above the breadcrumbs in your Shop Page. You could use the woocommerce_before_main_content action.

function BannerShop(){

  if(is_shop()){
    echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
  }
}
add_action( 'woocommerce_before_main_content', 'BannerShop', 10 );

Here i show the before and after. BTW I don't know what theme are you using so it may be displayed different.

Before https://i.sstatic.net/Mv2YK.jpg

After https://i.sstatic.net/nTfCa.jpg

Upvotes: 1

Related Questions