Chykalophia homepage
Change Yoast Sitemap Frequency And Priority

Change Yoast Sitemap Frequency And Priority

To Change Yoast Sitemap Frequency And Priority you need to use a little bit of custom code (using filters). Thankfully there is some documentation out there about it (links: change sitemap frequency documentation, change sitemap priority documentation) though it’s not good documentation and it’s rather confusing. So let’s demystify this code and let you quickly and easily change Yoast sitemap frequency and priority.

Adding custom code should be done by using a custom ‘functions.php’ file in your child theme, though if you don’t know what a child theme is or how to make a fuctions.php file, or are afraid to touch code via ftp, that’s ok you can use a very handy plugin called My Custom Functions. It’s a plugin I’ve used on several client sites and it works great since then I don’t need any FTP access and can add custom code through that function … which as you can image makes life a lot easier.

There are two parts to this post: changing the sitemap update frequency and changing the sitemap priorities for updates. Let’s start with frequency.

Change Yoast SEO Sitemap Frequency

This one is the more confusing of the two because of how you have to use it. The documentation says that the function name looks like this:

'wpseo_sitemap_' . $filter . '_change_freq'

The problem is what does ‘$filter’ mean, how do we use it and what are our options?

We’re also told that our choices for what value to return (meaning what frequency to set) are limited to:

'always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'

Before we go any further I need to explain something to you: thankfully the content of our custom code (where we return the result) is very very simple, though it can be more complex depending on how much heavy filtering you want to do. Our whole custom function is one single line of code: return the desired frequency rate text.

Thus, our custom function will look something like (if we want to change the frequency to be daily for example):

function my_custom_freq( $default, $url ) {
    return 'daily';
}

To explain that code above:

  • We created a function named “my_custom_freq”, though you can name yours anything you (reasonably) want.
  • Our function accepts two parameters: one named “$default” and the other named “$url”.
  • $default is the frequency that’s set by Yoast SEO by initially for the selected page/post/thing we’re changing.
  • $url is …. the url.
  • Since our code here is simple, we simply return the result “daily” to give everything from the select page/post/thing type to have a daily refresh rate.

So far easy, yes? Now the confusing page.

When I say “page/post/thing type” … that’s what will go and replace the “$filter” that we talked about in the beginning.

Your basic option for $filter are (but not limited to):

  • homepage
  • blogpage
  • post_archive
  • page_archive
  • post_single
  • page_single
  • author_archive

See a pattern forming here? Thus based on the content and setup of your WordPress site you can have $filter be something such as:

  • product_single
  • product_archive
  • product_cat_single
  • product_brand_single
  • mycustomposttype_single
  • mycustomposttype_archive

and so on. But wait! There’s more … well, one more (for now):

  • postTaxonomy_term

Where ‘postTaxonomy’ would be that post types category or tag general name, for example (using WooCommerce Product Brands) we could have “wpseo_sitemap_product_brand_term_change_freq” since Product Brand is yet another type of categorization you can do in WooCommerce (if you get the brands plugin).

Thus the full line would be something like:

add_filter( 'wpseo_sitemap_product_single_change_freq', 'my_custom_freq', 10, 2 );

There we are adding a filter to WordPress based on the Yoast SEO data which is categorized (by Yoast, and yes … this specific language is specific to Yoast SEO plugin) by wpseo_sitemap_product_single_change_freq. See how the $filter became the post type we wanted? Just in case if you didn’t know, anything other than a regular ol’ post or page in WordPress IS just a fancy custom post type … meaning, for example, a WooCommerce Product is just a custom post type with the name Product.

So putting it all together we get:

add_filter( 'wpseo_sitemap_blogpage_change_freq', 'my_custom_freq', 10, 2 );

function my_custom_freq( $default, $url ) {
    return 'daily';
}

If you want to have the frequency be daily for more thing you do not have to rewrite all that code, simply add another filter for your wanted post type thingy and point it towards your custom function:

add_filter( 'wpseo_sitemap_product_single_change_freq', 'my_custom_freq', 10, 2 );
add_filter( 'wpseo_sitemap_homepage_change_freq', 'my_custom_freq', 10, 2 );
add_filter( 'wpseo_sitemap_blogpage_change_freq', 'my_custom_freq', 10, 2 );
add_filter( 'wpseo_sitemap_post_single_change_freq', 'my_custom_freq', 10, 2 );
add_filter( 'wpseo_sitemap_product_archive_change_freq', 'my_custom_freq', 10, 2 );
add_filter( 'wpseo_sitemap_page_single_change_freq', 'my_custom_freq', 10, 2 );
add_filter( 'wpseo_sitemap_product_brand_term_change_freq', 'my_custom_freq', 10, 2 );
add_filter( 'wpseo_sitemap_product_cat_term_change_freq', 'my_custom_freq', 10, 2 );

function my_custom_freq( $default, $url ) {
    return 'daily';
}

 

Change Yoast SEO Sitemap Priority

This one, at least I think so, is pretty simple. We have two functions we can filter on: either for the single posts or for the archives.

wpseo_xml_sitemap_post_priority
wpseo_xml_post_type_archive_priority

There’s no name changing or anything here just two simple filters. I’ll use the sitemap_post filter in our example:

add_filter( 'wpseo_xml_sitemap_post_priority', 'my_custom_post_xml_priority', 10, 3 );

function my_custom_post_xml_priority( $return, $type, $post) {
    if ($type == 'page')
    	$return = 0.6;
    else if ($type == 'post')
        $return = 0.8;
    else if ($type == 'product')
        $return = 0.8;
    return $return;
}

At the top we simple call the filter just once, no more is needed, and then do the filtering inside the code. In this example I simply filter by the post type. To help explain the code:

  • We named our custom function “my_custom_post_xml_priority”.
  • It accepts three parameters: the return value, the post type and the actual post
  • Inside the code we set the return value ($return) based on the post type we’re filtering for
  • The value can only be between 0 and 1 (between 0.00 and 1.00 .. two point decimal)
  • And then we simply return the value named $return.

Simple. :)

Essentially, the $filter value from the frequency setting now is set inside the code instead of on the filter name.

If you’re looking for more, looking for more documentation on the sitemaps priority and frequency and live examples click the image below to get your FREE copy of the Chykalophia Yoast SEO Code Extras.

CTA-Graphic1

The Next Draft Newsletter

Get our top branding, UX and website resources for your business straight to your inbox.

Resources Page Mega Email Signup

This will add you to our Next Draft list where we send out useful content around branding, marketing, and all things website that help inspire growth for you and your business. Of course you can unsubscribe anytime.

Get started on a branding or website project with us.

GET ON A CALLBook a brand, UX, or web audit