WordPress
HTML
CSS
JavaScript
jQuery
SQL
PHP
WordPress Snippets

Code Snippet

After doing a migration from Yoast SEO to The SEO Framework, you may find that you cannot get rid of the /sitemap_index.xml file which is no longer needed since it was the Yoast version.

The SEO Framework creates a sitemap at /sitemap.xml on the fly, and this is the one we’d like to use. And even though Yoast also creates their version of the sitemap at /sitemap_index.xml on the fly, and you’ve deleted the Yoast plugin, the file still “lives” in that location somehow.

I’m told it’s actually a hosting issue (don’t know).

No worries though, because it’s now been taken over by The SEO Framework, which also keeps its sitemap at /sitemap.xml. This means that you now have exact duplicate sitemaps living in two locations.

Not a big deal.

However, you may be uncomfortable with this, as it seems wrong. But since the file doesn’t actually exist, you can’t simply go in with FTP and delete it.

But with the following code, you can kill it off making The SEO Framework /sitemap.xml the only sitemap.

PHP

Place the following code anywhere in your theme’s functions.php document.

				
					add_filter( 'the_seo_framework_sitemap_endpoint_list', function( $list ) {
        if ( isset( $list['base'] ) ) {
            // set human-readable name
            $list['base']['endpoint'] = 'sitemap.xml';
            // set custom computer name
            $list['base']['regex']    = '/^sitemap\.xml/';
            // remove from robots.txt listing
            $list['base']['robots']   = false;
        }
        // remove yoast /sitemap_index.xml
        unset( $list['index'] );
        
        return $list;
    } );
				
			

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.

WordPress
HTML
CSS
JavaScript
jQuery
SQL
PHP

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.