7

I have set the "shop" page as my front page and I want to remove the default woocommerce title from the home page of the site. I have emptied the title but I still get an empty tag like this on the home page:

<h1 class="woocommerce-products-header__title page-title"></h1>

This creates an empty area above the content which is annoying. I have tried the following solutions and they work BUT the title page for category pages would be removed too. I want the title only at the home page be removed.

  1. First solution: I added the following code to my style:

    .woocommerce-page .page-title {
    
     display: none;
    
    }
    
  2. Added the following to function.php

    add_filter('woocommerce_show_page_title', '__return_false');
    

I repeat, these solutions do what they are supposed to but I want the page-title for categories remain and only the title for the home page be removed.

1
  • beware that this filter only works, if you declare theme support. i was going nuts on why this was not working for me at all..
    – honk31
    Mar 13, 2019 at 17:06

6 Answers 6

1

you can overwrite woocommerce template of "archive-product.php" into your current theme and replace with this code.

<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>

            <?php if(!is_shop()) { ?>
            <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
            <?php } ?>
<?php endif; ?>

For reference conditional tag of woocommerce

OR

<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>

                <?php if(is_product_category()) { ?>
                <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
                <?php } ?>
 <?php endif; ?>
2
  • This file is in plugins folder. Doesn't change of it defeat the purpose of creating a child theme? I mean can't I change things inside my child theme so I don't need to be worried about any updates or changes that plugins create? Nov 23, 2017 at 18:47
  • yes no any defeat to plugin update when you override template into theme. reference for how to override woocommerce template file in child theme : v4.datafeedr.com/documentation/580 Nov 24, 2017 at 3:53
7

Instead of hacking templates, you can put this in functions.php of your child theme:

add_filter( 'woocommerce_show_page_title', 'not_a_shop_page' );
function not_a_shop_page() {
    return boolval(!is_shop());
}
4
  • I don't know how....but this works!
    – klewis
    Jun 3, 2019 at 20:45
  • 1
    Filter woocommerce_show_page_title shows page title if provided argument is true. The function makes argument true for all pages that are "not a shop page" and false for shop page. Jun 3, 2019 at 21:18
  • Got it, but I guess I was never in a position to use return boolval in WordPress to determine if I was on the shop page or not. I would argue that part should be easier for to write.
    – klewis
    Jun 4, 2019 at 12:05
  • Unfortunately, this does not remove the HTML <header class="woocommerce-products-header"> </header> Jul 27, 2021 at 11:01
2

Hello you can do this thing and i hope this work for you also

 <?php
    if (!is_shop()) {
      if ( apply_filters( 'woocommerce_show_page_title', true ) ) {  ?>
            <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
 <?php   }else{ ?>
      <h1 class="page-title"><?php echo ''; ?>
    }
  } ?>

For More Prefer this link

2

To remove the title only from the product page you need to add this code to your css styles

.product-template-default .woocommerce-products-header {
   display: none;
}
1

Few alternate ways to do so:

  1. Remove title code from your theme's home.php
  2. Create a template for products page
  3. For homepage, if you are using frontpage.php then it is quite easy to remove it from there. Else, you can use the last point mentioned below
  4. Go to your page.php and write a simple conditional statement to check if it is a homepage or not. A reference of this conditional statement from WP codex is here

https://developer.wordpress.org/reference/functions/is_home/

0

I just did this for my website, but in a more round about way.

  1. I edited my archive-product.php file in the theme file editor and changed:

<h1 class="entry-title"><?php woocommerce_page_title(); ?></h1>

To:

<h6 class="entry-title"><?php woocommerce_page_title(); ?></h6>

  1. I then edited the stylesheet page and added:

h6 {display: none;}

Obviously you shouldn't use this solution if you have h6 titles in your code, but for a simple solution, it does the trick.

1
  • You could just use h6.entry-title instead of a generic h6 - that at least will reduce the scope of the rule. Sep 27, 2022 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.