Skip to content

Instantly share code, notes, and snippets.

@tallesairan
Created September 13, 2021 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tallesairan/d1e0b330fd451229d3c4bba933a5b241 to your computer and use it in GitHub Desktop.
Save tallesairan/d1e0b330fd451229d3c4bba933a5b241 to your computer and use it in GitHub Desktop.
Yoast sitemap preloader
<?php
ignore_user_abort( true );
define( 'WP_USE_THEMES', false );
define( 'DONOTCACHEPAGE', true );
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
ini_set('memory_limit','6G');
$sitemapIndex = home_url('sitemap_index.xml');
$sitemapIndex = json_decode(json_encode(simplexml_load_file($sitemapIndex) ), TRUE);
foreach($sitemapIndex['sitemap'] as $sitemapFile){
@$body = file_get_contents($sitemapFile['loc'], false, stream_context_create([
'http' => [
'timeout' => 60,
'header' => [
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36',
'Upgrade-Insecure-Requests: 1',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Language: es_ES'
],
'request_fulluri' => true,
],
]));
if($body){
echo $sitemapFile['loc']." Ok ! \n";
}
sleep(5); // 5s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment