PrestaShop Pro-Tip: Hiding Category Images on Specific Pages with CSS

PrestaShop Pro-Tip: Hiding Category Images on Specific Pages with CSS

As an e-commerce platform, PrestaShop offers extensive customization options, but sometimes achieving a very specific visual tweak requires a clever approach. A common request from merchants and developers alike is the ability to control the visibility of elements on a page, not globally, but for particular instances. This community insight from the PrestaShop forum highlights a perfect example: conditionally hiding category images.

The Challenge: Selective Category Image Visibility

A PrestaShop user, FS47, presented a common dilemma: they wanted to hide the main category image, but only for certain categories. The default options proved insufficient:

  • Deleting the image from the back office: This action removes the image entirely, including its thumbnail, which might not be the desired outcome if the thumbnail is still needed elsewhere or if the image needs to be easily restored.
  • Applying general CSS: A simple CSS rule like
    .category-cover>img { display: none !important; }
    effectively hides all category images across the entire store. This is too broad when only specific categories should be affected.

The core of the problem was how to "target" a specific category with CSS without resorting to complex module development or core file modifications, which are generally discouraged due to update compatibility issues.

The Elegant Solution: Leveraging PrestaShop's HTML Structure

Fortunately, the PrestaShop community, specifically Eolia, quickly provided an elegant and straightforward CSS-based solution. The key lies in understanding how PrestaShop renders its HTML, particularly the tag.

PrestaShop intelligently adds classes to the tag that reflect the current page context. When viewing a category page, the tag will include classes such as category, followed by category-ID (where ID is the numerical identifier of the category), and often the category's slug (e.g., category-robes).

For instance, a category page for "Robes" with an ID of 8 might have a tag resembling this:

This structure provides a powerful hook for targeted CSS. By combining the specific category class (e.g., .category-8) with the existing CSS selector for the category cover image, you can create a rule that applies only to that particular category.

Implementing the Targeted CSS

To hide the category cover image exclusively for category ID 8, the CSS would look like this:

.category-8 .category-cover>img {    display: none !important;}

This rule tells the browser: "Only when the body element has the class category-8, find an element with the class category-cover within it, and then hide its child."

If you need to hide images for multiple specific categories, you can extend this by adding more rules or combining selectors:

.category-8 .category-cover>img,.category-15 .category-cover>img,.category-22 .category-cover>img {    display: none !important;}

This CSS should be added to your theme's custom CSS file or through a module that allows custom CSS injection. This ensures that your changes persist across theme updates, provided you're not directly modifying core theme files.

Why This Approach is Valuable for PrestaShop Merchants and Developers

This solution is highly valuable for several reasons:

  • Precision: It allows for granular control over design elements on a per-category basis.
  • Simplicity: It's a pure CSS solution, requiring no PHP, Smarty template modifications, or module installations for this specific task.
  • Maintainability: As long as PrestaShop continues to output category IDs in the class (which is a stable and fundamental part of its front-end architecture), this solution will remain robust.
  • Flexibility: The same principle can be applied to target other elements or apply different styles based on the current category. For example, you could change background colors, text styles, or hide other blocks for specific categories.

Understanding the structure of PrestaShop's generated HTML is a powerful skill for any merchant or developer looking to customize their store's front end. This simple trick demonstrates how a quick inspection of the page source can unlock numerous possibilities for theme customization, enhancing the user experience and visual appeal of your PrestaShop store without deep technical intervention.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools