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:

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:

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):

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:

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:

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:

 

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.

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

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

  • Thanks for sharing very helpful post.
    Can you let me please how we can set below priority ?

    Main Categorie : 80
    Subcategorie : 70
    Subsubcategorie : 60
    Main Page : 100
    Other Pages – 60

    Thanks

  • Hi,
    I try to address specific posts but it doesn’t work. Here is an example for what I try to:

    add_filter( ‘wpseo_xml_sitemap_post_priority’, ‘my_custom_post_xml_priority’, 10, 2 );

    function my_custom_post_xml_priority( $return, $type, $post) {

    if ($type == ‘page’)

    {

    if ($post == ‘6’ || $post == ‘9’ || $post == ’18’ || $post == ’11’ || $post == ’13’)

    {

    $return = 1.00;

    }else{

    $return = 0.5;

    }

    return $return;

    }

    }

    • Hey Tiit, I go over that in the free code package. :)

      What you’ll have to do is filter by product category in the function by doing something like:

      if type = product…
      … get product id
      … if get_product_category (product id) =
      … … do stuff

      Something like that.

  • Hi guys. I’m struggling finding a solution to implement this code…
    I’m trying different ways to give a different priority only to certain page (or posts). This is my code… it return priority 0.5 to all pages… obviously wordpress don’t like my first “if” condition, or it’s wrong…
    Any help?

    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’) {

    switch ($post) {

    case ‘8’:

    case ‘395’:

    case ‘342’:

    $return = 0.9;

    case ‘5’:

    $return = 1.00;

    case ‘620’:

    case ‘703’:

    case ‘603’:

    case ‘688’:

    case ‘695’:

    case ‘614’:

    case ‘684’:

    case ‘639’:

    case ‘628’:

    case ‘539’:

    case ‘542’:

    case ‘521’:

    case ‘509’:

    case ‘517’:

    case ‘528’:

    case ‘533’:

    case ‘536’:

    case ‘548’:

    case ‘545’:

    case ‘525’:

    case ‘551’:

    $return = 0.7;

    break;

    default:

    $return = 0.5;

    break;

    }

    }

    elseif ($type == ‘post’) {

    $return = 0.8;

    }

    return $return;

    }

  • For some reason I can’t change the home page frequency to daily. I have the following:

    add_filter( ‘wpseo_sitemap_homepage_change_freq’, ‘my_custom_homepage_freq’, 10, 2 );

    function my_custom_homepage_freq( $default, $url ) {
    return ‘daily’;
    }

    All pages including the home page are set to weekly. Any ideas?

      • I have the following but the frequency on the home page still says weekly:

        /* Change XML Sitemap frequency tags */
        add_filter( ‘wpseo_sitemap_homepage_change_freq’, ‘my_custom_homepage_freq’, 10, 2 );
        function my_custom_homepage_freq( $default, $url ) {
        return ‘daily’;
        }

        add_filter( ‘wpseo_sitemap_page_single_change_freq’, ‘my_custom_page_single_freq’, 10, 2 );
        function my_custom_page_single_freq( $default, $url ) {
        return ‘weekly’;
        }

  • Hi there,

    I can’t tell if this is a bug, or if I have implemented the following code incorrectly. For clarity, I’ve added this to the end of my theme’s functions.php file:

    add_filter( ‘wpseo_xml_post_type_archive_priority’, ‘my_custom_post_type_archive_xml_priority’, 10, 3 );
    function my_custom_post_type_archive_xml_priority( $return, $type, $post) {
    if ($type == ‘news’)
    $return = 0.8;
    return $return;
    }

    I would expect that to override the Priority for ‘news’ on the category sitemap: http://www.flickreel.com/category-sitemap.xml – but it would appear that it has no effect. In fact, having tried all of the code in this tutorial (under the heading ‘Change Yoast SEO Sitemap Priority’): https://chykalophia.com/wordpress/change-yoast-sitemap-frequency-and-priority/ – nothing on there seems to have any effect…

    Thanks for any help,
    Theo.

    • Just in case anyone else has this query, I got this response from a Yoast team member:

      “The filter that you are attempting to use applies to the main URL only (or some variation of it). There’s another filter for posts/pages. Currently, there is not a filter that adjusts taxonomies like categories or tags.

      The priority of categories is based on the number of posts in that category. The more posts assigned to the category, the higher the priority. Publishing more into a category is going to push this number up for you. This allows the plugin to dynamically respond to changes in your publishing patterns over time and for Google to be pointed to topics that you are spending a lot of time on.”

      I’m not sure that is necessarily the correct approach for them to take on this – particularly as for a website like Flickreel, ‘Reviews’ is essentially acting as a page, and at present, pages such as ‘about’, ‘contact’, ‘staff’ have a higher priority when they are never really changed. I will update you all on anything more that they say on the topic…

  • In fact, it is possible to change any of these with filters. Here is the code for anyone who would like to see how:

    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.2;
    return $return;
    }

    add_filter( ‘wpseo_sitemap_entry’, ‘my_custom_term_priority’, 10, 3 );

    function my_custom_term_priority( $url, $type, $term) {
    if ($type == ‘term’) {
    if($term->slug == ‘news’ || $term->slug == ‘reviews’ || $term->slug == ‘trailers’) {
    $url[‘pri’] = 0.8;
    $url[‘chf’] = ‘daily’;
    } else if ($term->slug == ‘previews’ || $term->slug == ‘features’) {
    $url[‘pri’] = 0.8;
    }
    }
    if($type == ‘user’) {
    $url[‘pri’] = 0.4;
    $url[‘chf’] = ‘weekly’;
    }
    return $url;
    }

  • Hi Guys! Thanks for the Wonderful work! I am trying to use the function changing the priority. I just copy/pasted the code in my functions.php but it doesn’t change the sitemap.xml….Do we just need to wait a bit? is it not instant?
    Many thanks guys!

    • Hey Guys, actually works like a charm, just needed to add
      add_filter(‘wpseo_enable_xml_sitemap_transient_caching’, ‘__return_false’);
      in the functions.php so it force refresh the sitemap!
      I think it’s best to remove this line once sitmap has been updated correctly,

      Have a great Sunday!

  • Hi and thank u for this useful article.

    Concerning “Change Yoast SEO Sitemap Priority”: I’m wondering if there is any way to target a specific page (id), because after setting all the pages to 0.8 even the frontpage is at Prio 80%. So how can I do that?

    I think this is wonderful function. And will help with the problem I’m having with subpages that automatically is set to prio 60%.

  • Hi, i already trying the code for changing the priority and it works. but i need to change the priority for
    category product and tag? Anyone can help? I try this, the other works except the category..

    add_filter( ‘wpseo_xml_sitemap_post_priority’, ‘my_custom_post_xml_priority’, 10, 4 );
    function my_custom_post_xml_priority( $return, $type, $post) {
    if ($type == ‘page’)
    $return = 1.0;
    else if ($type == ‘post’)
    $return = 0.6;
    else if ($type == ‘product’)
    $return = 0.6;
    else if ($type == ‘category’)
    $return = 0.9;
    return $return;
    }

  • I need to set the priority for the product category
    it is possible to change the priority of product category and post category
    I am able to change the frequency but priority is not changing
    Can some one help on this
    Thanks in advance.

  • Chicago

    931 Hinman Ave. 3, Evanston IL
    +1.844.413.9613

    Bali

    931 Hinman Ave. 3, Evanston IL
    +1.844.413.9613

    Business Learning Platform

    Women Community Project

    Receive quarterly updates on all the latest from ARI & PETER

    Copyright © 2011 – 2020 Chykalophia Group, LLC. All rights reserved.
    >