admin管理员组文章数量:1122832
trying to add a query string for every products and product category pages onto sitemap so google can index them properly. My sitemap is generated by yoast seo plugin for wordpress.
This query string ?wmc-currency=AUD will direct users to a product page, showing Australian dollar as currency
I have a total of 3 different currencies, AUD, USD, and GBP.
A product link without any query string will be directed to the default page showing USD currency.
So what I am trying to achieve is adding extra URLs with query string to the default sitemap. Is this possible?
trying to add a query string for every products and product category pages onto sitemap so google can index them properly. My sitemap is generated by yoast seo plugin for wordpress.
This query string ?wmc-currency=AUD will direct users to a product page, showing Australian dollar as currency
I have a total of 3 different currencies, AUD, USD, and GBP.
A product link without any query string will be directed to the default page showing USD currency.
So what I am trying to achieve is adding extra URLs with query string to the default sitemap. Is this possible?
Share Improve this question asked Sep 17, 2024 at 7:41 Spriteboy82Spriteboy82 1 1- If it's a sitemap generated by Yoast, you should check with Yoast's support team. Third-party plugin support is off topic here. – Pat J Commented Sep 19, 2024 at 15:13
1 Answer
Reset to default 1If you want to add ?wmc-currency=AUD
for all of your product URLs in the sitemap, you can use the wpseo_xml_sitemap_post_url
filter:
/**
* Alters the URL structure for all products
*
* @param string $url The URL to modify.
* @param WP_Post $post The post object.
*
* @return string The modified URL.
*/
function sitemap_product_url( $url, $post ) {
if ( $post->post_type === 'product' ) {
$url .= '?wmc-currency=AUD';
}
return $url;
}
add_filter( 'wpseo_xml_sitemap_post_url', 'sitemap_product_url', 10, 2 );
If you want to add extra URL for other currencies, you can then generate an additional sitemap, and then include that sitemap for indexing using the following code:
* Writes additional/custom XML sitemap strings to the XML sitemap index.
*
* @param string $sitemap_custom_items XML describing one or more custom sitemaps.
*
* @return string The XML sitemap index with the additional XML.
*/
function add_sitemap_custom_items( $sitemap_custom_items ) {
$sitemap_custom_items .= '
<sitemap>
<loc>http://www.example.com/external-sitemap-1.xml</loc>
<lastmod>2017-05-22T23:12:27+00:00</lastmod>
</sitemap>';
return $sitemap_custom_items;
}
add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );
Reference: Yoast SEO Sitemap API
本文标签: phpHow to add query string at the end of sitemap Yoast SEO
版权声明:本文标题:php - How to add query string at the end of sitemap Yoast SEO 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736290755a1928579.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论