InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Wordpress customization tutorials

  • Handle pagination in wordpress custom php code
  • How to and why disable wordpress cron
  • How to customize wordpress image alt tag
  • How to display date in wordpress pages
  • How to display wordpress page list with specific custom field value
  • How to display wordpress top level pages
  • How to hide a post from home and RSS feed in wordpress
  • How to include bootstrap javascript and css in wordpress post
  • How to include wordpress pages in archives
  • How to override priority and change frequency in Yoast xml sitemap
  • How to remove xmlrpc from wordpress headers
  • How to setup wordpress custom query params with pretty url format
  • How to show wordpress pages on front page with skip_home custom field
  • How to use google custom search for wordpress site
  • How to write custom php in wordpress
  • No frills social share links for Wordpress sites
  • Using Wordpress custom field for displaying code
  • Wordpress - add content filter after shortcode execution
  • Wordpress - customize category and tag links
  • Wordpress - customize facebook plugin opengraph meta tags
  • Wordpress - customize posts per page for tag, category and date archive pages
  • Wordpress - exclude specific posts from archive pages
  • Wordpress - get posts/pages with missing meta key
  • Wordpress - how to add filter to description meta tag
  • Wordpress - how to create custom tag cloud
  • Wordpress - how to exclude specific tag posts from a tag archive page
  • Wordpress - write custom php log to separate file
  • Wordpress how to check if a post is being viewed by admin
 
  • Home
  • > Tutorials
  • > Wordpress
  • > Wordpress customization

How to override priority and change frequency in Yoast xml sitemap

By admin on Jan 11, 2016

It is important to maintain healthy xml sitemap for your site. In case you are using Yoast SEO plugin to generate xml sitemap for a wordpress site, it provides some hooks to override priority and change frequency of various urls.

wordpress-xml-sitemap

Here is wordpress code snippet to customize xml sitemap generated by Yoast seo plugin.

add_filter('wpseo_sitemap_entry', 'my_sitemap_priority', 10, 3);
function my_sitemap_priority($url, $sitemap_type, $contextobj) {
  $newurl = $url;
  // tag sitemap
  if ($sitemap_type == 'term') {
    // change frequency
    // replace this with your logic
    $newurl['chf'] = 'daily';
    // priority
    // replace this with your logic
    if ($url['pri'] <= 0.6) {
      $newurl['pri'] += 0.2;
    }
  } else if (in_array($sitemap_type, array('post', 'page'))) {
    // replace these with your logic
    $newurl['chf'] = 'daily';
    $newurl['pri'] = 0.8;
  }
  return $newurl;
}

Few points to note

  1. $contextobj contains either $post or $tag object.
  2. The default priority and frequency should work in most cases. You should customize these only if you know what you are doing.
  3. Max priority value can be 1.0 and these values are only relative for all urls on your site.
  4. For more information you may want to see file class-sitemaps.php in your plugin directory.

Suggested posts:

  1. Mac command line utility open – some handy tips for better productivity
  2. How to setup wordpress custom query params with pretty url format
  3. WordPress – query to find term_taxonomy_id from category name
  4. jQuery – difference between html() and text()
  5. Svn – how to view older version of a file
  6. Using camtasia to generate screencast video on your computer
  7. How to and why disable wordpress cron
  8. How to use your own domain name for feedburner feed urls
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Tutorials, Web Development, Webmaster, Wordpress, Wordpress customization
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress