Filter For Product Category Also Controlling Single Product Pages

#423686
  • Resolved Will
    Rank Math free

    Hi there,

    Thank you for providing Rank Math plugin which I really appreciate.

    However, I have an issue with several filters I am using.

    I want RankMath to control all the SEO on my site, but I need to remove certain tags from just product category pages.

    For example, I am using the following code to remove RankMath generated <title> tags from just product category URLs:

    /**
    * Allow changing of the RankMath <title> tag.
    *
    * @param string $title.
    */
    add_filter( ‘rank_math/frontend/title’, function( $title ) {
    if (is_product_category())
    return false;
    });

    This is working, but it is also removing the RankMath <title> tag from single product description pages as well, which I need to keep in place.

    I have tried disabling other plugins in case there is a conflict and still can’t get this to work just for product category URLs.

    The same issue occurs if I use (is_archive) this is also changing the single product pages.

    Is there a line I can add to the code to ensure this doesn’t affect the single product page?

    Many thanks

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

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

    Try unsetting the $title instead of returning false. Refer to this filter code:

    add_filter( 'rank_math/frontend/title', function( $title ) {
      if (is_product_category()){
        unset($title);
      }
      return $title;
    });

    If that doesn’t work, you may also try this:

    add_filter( 'rank_math/frontend/title', function( $title ) {
      if (is_product_category() || !is_product()){
        unset($title);
      }
      return $title;
    });

    Let us know if this will work on your end.

    Looking forward to helping you.

    Will
    Rank Math free

    Hi Jeremy,

    The second snippet you provided is now working perfectly for my needs.

    Thanks so much for your help!

    Best regards,

    Will

    Hello,

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

    If you don’t mind us 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 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.

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

The ticket ‘Filter For Product Category Also Controlling Single Product Pages’ is closed to new replies.