4

How can i remove category title (H1) from a specific page of catalog? I deleted breadcrumbs using a code xml:

 <remove name="breadcrumbs"/>

Is it possible to replicate this with H1? Thanks!

4 Answers 4

8

Unfortunately you cannot do that via xml layouts only.
But you have a few other options. All of them require some coding.

Option 1 - Quick and dirty
Edit app/design/frontned/{package}/{theme}/catalog/product/category/view.phtml and add an if statement around the h1 tag. Something like this:

if ($_category->getId() != 44) { //your category id here
    //h1 tag here
}

Option 2 - with attributes.
Add a new yes/no attribute to the category called hide_title.
Then you need to edit the same template as in option 1 and add this if statement

if (!$_category->getHideTitle()) {
    //h1 tag here
}

I would use this approach. This way you can always hide the title from the backend for every category you need.

Option 3 - no attributes but a new theme.
Create a new theme inside your package.
Let's call it no_title.
This theme should contain only one file. The category view template:
app/design/frontned/{package}/no_title/catalog/product/category/view.phtml.
This has to be a clone of your normal view file from your theme with just the h1 tag removed.
Then, for the categories you don't want the title you set them to use this new theme from the design settings tab in the backend.

4
  • Thank you! In my opinion the third option is the most correct! Commented Sep 15, 2014 at 11:57
  • I don't know why, but option 3 bugs me. Creating a new theme to be used only for a single category page's template seems awkward. Option 2 seems like it would be more obvious to the next guy.
    – pspahn
    Commented Feb 17, 2015 at 18:13
  • I didn't say option 3 is the best. i sayd it can be a solution. i would actually do this. for example, if i latrer change the theme of my website i can still use the one i created for the special categories without having to modify my new theme (lets say i bought my new theme online).
    – Marius
    Commented Feb 17, 2015 at 18:22
  • This can now be done with XML layouts, see my answer below Commented Sep 27, 2022 at 15:36
3

Option 4 - You can add this under the "custom design" tab in a category. Just copy the original view.phtml. Edit the title section to either remove it or comment out.

The path to this file is: /your_theme/template/catalog/category/

<reference name="category.products">   
 <action method="setTemplate">       
  <template>catalog/category/your-view.phtml</template>   
 </action>
</reference>

Cheers ~ Happy Coding!

1

This cannot be done in a pure XML method. However it can be done via the admin for a specific category. Admin -> Catalog -> Manage Categories -> select the category to edit -> click Custom Design tab -> inside Custom Layout Update add this code:

<reference name="before_body_end">
    <block type="core/text" name="hide.heading">
      <action method="setText">
        <text>
           <![CDATA[
                <style type="text/css">
                    .category-title { display: none; }
                </style>
            ]]>
            </text>
        </action>
    </block>
</reference>
1
  • This can now be done with XML layouts, see my answer below Commented Sep 27, 2022 at 15:37
0

This CAN NOW be done with XML in versions >= 2.3.4

in: app/design/frontend/VENDOR/THEME_NAME/Magento_Catalog/layout/

create: catalog_category_view_selectable_[CATID]_[CATNAME].xml

where [CATID] is the ID of the Category and [CATNAME] is the lowercase name of the category with all spaces removed. eg: Womens Dress Skirts becomes womensdressskirts

add code:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="3columns" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="page.main.title" remove="true" />
    </body>
</page>

Now in admin > catalog > Categories > (eg)Womens Dress Skirts, under Design you'll see a dropdown labelled Custom Layout Update. Change that to (eg) womensdressskirts. Save, clear your cache and the H1 will be gone.

Works with any block on any specific category.

Learned from Rakesh Jesadiya here: https://www.rakeshjesadiya.com/add-category-custom-layout-update-xml-file-magento-2-3-4/

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.