Display only Primary Category in product meta

  • Hello.
    Is there a way to display only the primary category in the meta data of a product on a single product page, in the product archive page and “related product” loop too ?

    I have each product on my store that belongs to only one category ( Merch, Records, Print or Goodies) and sometimes to the Preorder category as well (which is never set as primary category). I never want the “Preorder” category term to be displayed in meta data.

    Any idea how I could do that ?

    I’m working on a local environnement atm so here is a pic to show what I want to remove: https://ibb.co/znkwH41

    Thanks !

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Since as you say you only want to remove it from the place you marked in the picture, the easiest way would be with just some custom CSS in your theme (because you don’t want it to be displayed but you want it to be assigned to the product).

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Hello Alberto. Thanks for your answer.

    You’re right I want it to be assigned to the product but want it to be removed from 3 places : single product page, in the product archive page and “related product” loop.

    I’ve thought about using CSS to display:none the a:last-of-type which is “Preorder” on the pic but since the category terms are displayed in alphabetical order it doesn’t work as I have some categories like “Print” that would be displayed after “Preorder”.

    I also though about using some custom Javascript to target the <a> with innerhtml equals to “Preorder” to apply display:none in JS but felt that might be a cleaner way to do it directly in PHP by maybe using action / filter hooks in my child theme’s functions.php

    But maybe there is a simple CSS way to do it I didn’t think about ?
    Thanks !

    Hello,

    If you want, I can take a closer look and try to find a good CSS code for that. I would need you to add each of the pages where you want them removed to be added in the Sensitive Data section. Also, if you could add images of each of those pages where you mark me the elements you want to have deleted, it would make it easy for me.

    Looking forward to help you.

    Hello,

    I have updated the sensitive data as requested.
    I’ve also uploaded an online version of the website (I was working on local until now) to make it easier for you.

    Let me know if you find a solution to this problem !

    Thank you.

    Hello,

    Here is the code, I tried it in your website and it worked fine, please check it:

    // Code to remove the "preorder" element in Product Archive page and also at the bottom of the Single Product page
    ul.woo-entry-inner > li.category > a[href*="preorder"] {
        display: none;
    }
    
    // Since we had two elements in the top of the single product but we hide the "preorder" element, we need to hide the comma, we did it with this code
    .product_meta .posted_in {
       color: rgba(0,0,0,0);
    }
    
    // This removes the preorder link in the single product (at the top)
    .single-product .product_meta .posted_in a[href*="preorder"] {
        display: none;
    }

    Looking forward to help you.

    This works like a charm thanks !
    I’ve just tweaked the code to remove the coma as the one you posted only worked for the single product but not the related prodcut and product archive but it’s all good now .

    .product_meta .posted_in, .product-inner .category {
       color: rgba(0,0,0,0) !important;
    }

    Thanks a lot for the help !

    Hello Alexis,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

    Just posted a 5 stars review 🙂

    Hi Alexis,

    Thanks a ton for that.

    We really appreciate it.

    If you need help with anything else, please open a new support ticket here so we can help:

    https://support.rankmath.com

    We are always here for assistance.

Viewing 9 replies - 1 through 9 (of 9 total)

The ticket ‘Display only Primary Category in product meta’ is closed to new replies.