-
hi i want add a link to my site map
i see something in your developer api page
but that just can add link in page site map or post site map
i want add it to the woocommerce product category site mapAlso, I had another question, is it possible to update the lastmod date automatically? Or should we update manually?
-
Hello,
I apologize for the inconvenience you are facing. To add a link to your WooCommerce product category sitemap, you can follow these steps:
- Navigate to your WordPress Dashboard.
- Go to Rank Math SEO and enable the Sitemap module.
- Once enabled, you can view your XML sitemap by going to Rank Math SEO → Sitemap Settings.
- Copy the URL of the product categories sitemap from the top of the page.
If you want to include a link in your WooCommerce product category sitemap, you can save the URL and submit it to Google or reference it whenever needed.
Regarding your second question about updating the lastmod date automatically in the sitemap, Rank Math automatically updates the lastmod date of your sitemap whenever there is a change on your website. This ensures that search engines are informed about the latest updates on your site without manual intervention.
If you have any further questions or need assistance, please feel free to ask.
Thank you for reaching out and raising these concerns.
Sources:
How to Configure Sitemaps in Rank Math – Best Settings and Tips
What Are the SEO Benefits of Sitemaps? » Rank Math
Resolving Rank Math Schema Markup Related Issues
How to Use Product Schema for WooCommerce Products » Rank MathHello,
To add URLs manually in your product category sitemap, then you may need to use and customize this filter on your site:
/** Filter to add extra URLs to the XML sitemap by type. * Only runs for the first page, not on all. * @param string $content String content to add, defaults to empty. */ add_action( 'rank_math/sitemap/product_cat_content', function() { return '<url> <loc>https://website.com/test-product-cat/</loc> <lastmod>2024-02-29T20:20:20+00:00</lastmod> </url>'; });
And here’s how you can add a filter/hook to your WordPress site:
https://rankmath.com/kb/wordpress-hooks-actions-filters/Regarding the lastmod date, that is automatically set depending on the date it was modified from your WordPress.
Hope that helps.
Thanks, it worked
But about its date, I published a new product on that page, but its date was not updated and it shows the same time as you wrote in the code above.
Is this normal?
When the product is released, the cache is reset automatically, so it’s not a problem with the cache!
I should also say that this is a query that I have rewritten by rewrite_rule
Query:
?product_cat=theme&pa_cms=wp
Final link:
site.com/c/web/theme/wp
woo catefory: site.com/c/web/theme/
woo attribute: cms=wpbut the time of the “theme” category was updated
https://site.com/c/web/theme/
Because product is in this categoryHello,
Apologies for the confusion.
The lastmod for the URL that was added manually using the filter is not automatically updated, unlike the default category URLs.
However, if that page has some field where the updated date is getting saved, and that can be retrieved with PHP, then it’s possible.
It’s just a matter of retrieving those values into a variable and passing that variable into the filter.
For example, if you retrieve the data into a variable called
$updated_time
you could add it there like so:<lastmod>' . $updated_time . '</lastmod>
Hope that helps.
thank you,
I have just two more question that I will not open a new ticket because it is related to this explanation.
I created the rewrite rule, but it’s pagination points to my category page: “theme”
How should I edit the prev and next page for this page?
Also, the other(prev and next) pages of my categories are canonicalized to their first page, I want it to be the same for this page.my page: site.com/c/web/theme/wp
Thank you for helping me, I appreciate it
My second problem solved (canonical): I tested and found it to be correct with the same settings as before.
But my first problem still exists (prev and next link)
Hello,
If you want to change the adjacent link output, you can modify the following filter.
/** * Allow the changing of link rel output by Rank Math. * * @param string $link The full <code><link</code> element. * $rel can be next or prev */ add_filter( "rank_math/frontend/{$rel}_rel_link", function( $link ) { return $link; });
For example, if you want to change the
next
link for yourweb/theme
page URL, you can apply the filter like the following one:add_filter( "rank_math/frontend/next_rel_link", function( $link ) { $url = home_url( $_SERVER['REQUEST_URI'] ); if( (strpos($url,'web/theme') !== false) ) { $link = '<link rel="next" href="YOUR_PAGE_LINK_HERE" /> '; } return $link; });
Please make sure to change
YOUR_PAGE_LINK_HERE
with the actual adjacent link.Hope that helps and please don’t hesitate to let us know if you have any other questions.
Thank you.Thank you, but the next/prev pages are not a permanent link!
Is it not possible to specify the main page and make links to the next and prev pages based on that?
Currently my page issite.com/c/web/theme/wp/
and the next page points tosite.com/c/web/theme/page/2/
Because thissite.com/c/web/theme/wp/
link is a rewrite!Hello,
In this case, please use the following filter on your website and see if that works for you:
add_filter( "rank_math/frontend/next_rel_link", function( $link ) { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $url = home_url( $_SERVER['REQUEST_URI'] ); if (is_paged() || (strpos($url,'web/theme') !== false)) { global $wp; $current_url = home_url(add_query_arg(array(), $wp->request)); $current_url = preg_replace('/\/page\/\d+/', '', $current_url); $link = '<link rel="next" href="' . esc_url($current_url) . '/wp/' . ($paged + 1) . '" /> '; } return $link; }); add_filter( "rank_math/frontend/prev_rel_link", function( $link ) { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $url = home_url( $_SERVER['REQUEST_URI'] ); if (is_paged() || (strpos($url,'web/theme') !== false)) { global $wp; $current_url = home_url(add_query_arg(array(), $wp->request)); $current_url = preg_replace('/\/page\/\d+/', '', $current_url); $link = '<link rel="prev" href="' . esc_url($current_url) . '/wp/' . ($paged - 1) . '" /> '; } return $link; });
Let us know how it goes. Looking forward to helping you.
Thank you.
Thanks, it worked with a little editing.
about sitemap, Is it possible to set the date and time of a WooCommerce category on the sitemap for a custom link on the sitemap?
I was able to get this from the date of the last product in a category…
But this way is a bit unlikable!
Is it possible to do this through Rank Math? Or something else comes to your mind?Hello,
The last modified date of the taxonomy pages is taken from the last modified data of the most recently updated product/post in the category. There is no other way to fetch that, and if you want to use some other way to get the date, you will have to modify the filter. Such complex modifications fall out of the scope of our support, and you will have to do it yourself or get help from a profession developer.
Please do not hesitate to let us know if you need our assistance with anything else.
Hello, thank you. But I think you have misunderstood.
I have created a link: https://website.com/customlink/
I have added it in the sitemap with this code:add_action( 'rank_math/sitemap/product_cat_content', function() { return '<url> <loc>https://website.com/customlink/</loc> <lastmod>2024-02-29T20:20:20+00:00</lastmod> </url>'; });
I wanted to see it is possible to display the date of a product category for this link as well? in <lastmod>
Hello,
Thank you for your patience.
We’re not quite sure whether we fully understand your concern about the product category date.
Are you referring to multiple dates inside the lastmod tags?
Looking forward to helping you.
i want put the date of a product category in sitemap, to the my custom link date in sitemap.
is it possible?
You must be logged in to reply to this ticket.