Adding URLs to sitemap

#312748
  • Resolved Oded Talmon
    Rank Math free

    Hello,
    I added a parameter called ?lp for all Woocommerce Product pages, this parameter loads a different template for the single product page and is used as a service for clients that also creates a customized landing page.
    I would like to add all product urls with and without ?lp parameter, currently the sitemap only shows regular single product pages (without parameter).
    Which filter/action do I need to use in order to achieve something like that?

    Thanks!

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

    Thank you for contacting Rank Math today.

    You can use the following filter to add additional URLs to a specific type of sitemap: https://rankmath.com/kb/filters-hooks-api-developer/#add-extra-urls-in-sitemap

    You can create a loop to fetch all the product URLs and then append the query parameter to all of them.

    Hope this helps solve your issues.

    Don’t hesitate to get in touch if you have any other questions.

    Oded Talmon
    Rank Math free

    Hello Miguel and thanks for the quick reply!
    Do I need to return an array of those:

    '<url>
    <loc>https://rankmath.com/some-custom-url/</loc>
    <lastmod>2020-06-10T20:20:20+00:00</lastmod>
    </url>'

    for all products?

    Hello,

    They need to inside single quotes and each URL inside the appropriate tag.

    Here’s an example with two URLs:

    
    add_action( 'rank_math/sitemap/product_content', function() {
        return
            '<url>
                <loc>https://rankmath.com/some-custom-url/</loc>
                <lastmod>2020-06-10T20:20:20+00:00</lastmod>
            </url>
            <url>
                <loc>https://rankmath.com/another-url/</loc>
                <lastmod>2020-06-10T20:20:20+00:00</lastmod>
            </url>';
    });
    

    Hope this helps clarify your doubts.

    Don’t hesitate to get in touch if you have any other questions.

    Oded Talmon
    Rank Math free

    Got it! I’ll try that and let you know, thanks!

    Hello,

    Sure, if you need any other sort of clarification on any other filter or functionality just let us know.

    We are here to help!

    Oded Talmon
    Rank Math free

    Hello again,
    Which PHP function do I need to run in order to reach that date format?
    Should I try: $product->get_date_modified()->date(‘Y-m-d\TH:i:s\Z’)?
    Thanks

    Hello,

    The exact format to convert the date is the following:

    
    Y-m-d\TH:i:sP
    

    Don’t hesitate to get in touch if you have any other questions.

    Oded Talmon
    Rank Math free

    Alright, I’ve written this function but I don’t see any change in the sitemap xml.

    function nivbook_rankmath_sitemap() {
    	$html     = '';
    	$args     = array(
    		'status' => array( 'publish' ),
    		'limit'  => '-1',
    	);
    	$products = wc_get_products( $args );
    	
    	if( !empty( $products ) ) {
    		foreach( $products as $product ) {
    			$html .= '<url>
    			            <loc>' . $product->get_permalink() . '?lp</loc>
    			            <lastmod>' . $product->get_date_modified()->date( 'Y-m-d\TH:i:sP' ) . '</lastmod>
    			        </url>';
    		}
    	}
    	
    	return $html;
    }
    add_action( 'rank_math/sitemap/product_content', 'nivbook_rankmath_sitemap' );

    Sitemap URL: https://nivbook.co.il/product-sitemap.xml

    Hello,

    We tested that on our end and it’s working as expected and adding all the URLs but on your website, the sitemap might be getting cached.

    Please add the following filter before the function:

    
    add_filter( 'rank_math/sitemap/enable_caching', '__return_false');
    

    After that, please follow these steps and do a hard refresh of the sitemap page: https://i.rankmath.com/pipRDp

    Let us know if that helps.

    Looking forward to hearing back from you.

    Oded Talmon
    Rank Math free

    Amazing!
    Miguel, it’s been wonderful, I wish you all the best!

    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 11 replies - 1 through 11 (of 11 total)

The ticket ‘Adding URLs to sitemap’ is closed to new replies.