Yoast SEO for Wordpress is one of the most popular plugins with more than 5 million active installed. Yoast helps you with General SEO, Titles, Metas, Social tags, XML Sitemaps, etc.
If you are using this plugin and access sitemap, you will notice default frequency is weekly for a single post and the home page is daily.
If you are like me looking to change the single post frequency to daily or hourly then the following will help you.
Default sitemap frequency
I couldn’t find any way to change this using plugin GUI so below hack is done in functions.php of your theme.
As usual, take a backup of functions.php file
- Add the following to end the file
add_filter( 'wpseo_sitemap_post_single_change_freq', 'my_custom_post_freq', 10, 2 );
function my_custom_post_freq( $default, $url ) {
return 'daily';
}
- Save the file and refresh your sitemap URL
If you are looking to change the frequency to hourly then just change from daily to hourly in return as follows.
add_filter( 'wpseo_sitemap_post_single_change_freq', 'my_custom_post_freq', 10, 2 );
function my_custom_post_freq( $default, $url ) {
return hourly;
}
This is how my sitemap looks now after changing to daily.
It’s always recommended to make changes in your child themes so when you update your theme you don’t lose the custom changes.
Alternatively, if you are not using child theme then you can use Insert PHP plugin to insert the code.
Much better? Never thought it would be that easy to change the sitemap frequency.