Issue with Stripping HTML Tags from Product Titles in Sitemap

#913615
  • Steve Ayo
    Rank Math free

    Hello Rank Math Support Team,

    I’m using the Rank Math plugin to generate an HTML sitemap for my website, specifically for the page: https://starkbylwax.co.tz/sitemap/.

    The issue I’m encountering is that the product titles in the sitemap include HTML tags, and I’d like to strip those tags. I attempted to use the rank_math/sitemap/entry filter with the following code in my theme’s functions.php:

    add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ) {
    if ( $type === 'product' && isset( $url['title'] ) ) {
    $url['title'] = wp_strip_all_tags( $url['title'] );
    }
    return $url;
    }, 10, 3 );

    After adding this code, the product titles in the sitemap still include HTML tags. Could you confirm if this is the correct filter for modifying sitemap entries, or suggest an alternative way to achieve this?

    I’d appreciate your guidance on how to resolve this issue.

    Thank you!

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

    Thank you for contacting support.

    That filter cannot be used to change the title of the entries in the HTML sitemap. If the SEO titles of the items don’t have that HTML you can switch to that by going to WordPress Dashboard > Rank Math SEO > Sitemap Settings > HTML Sitemap.

    Otherwise, there are no other methods to change the title that is being displayed in the HTML sitemap.

    Steve Ayo
    Rank Math free

    Hello,

    Thank you for your prompt response. I understand that the rank_math/sitemap/entry filter cannot be used to modify the titles displayed in the HTML sitemap. However, I believe there must be a way to achieve this, perhaps through another filter or a custom approach.

    If I had more time, I would inspect the plugin code to identify the relevant hooks or methods myself, but I’d greatly appreciate it if you could forward this query to the development team for further assistance.

    Is there a way to intercept or modify the data being used to render the HTML sitemap titles programmatically? If not, could the development team suggest a workaround?

    Thank you for your time and understanding. I’m hopeful for a solution.

    Best regards,

    Hello,

    As we mentioned before, there are no ways to modify the title dynamically. You can either use the SEO title or the page title, but beyond that, there are no other ways to modify it.

    We don’t pass those values through any hook or filter, we just fetched them directly from the settings.

    Thank you.

    Okay,

    I have just custom coded something that feets my needs:

    Hello,

    That is fine.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

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

You must be logged in to reply to this ticket.