Question: How do you create and manage a sitemap using the Yoast SEO plugin in WordPress?


Yoast SEO is one of the most popular WordPress plugins that helps in managing your site's SEO, including creating and managing XML sitemaps. Here are the steps to create and manage a sitemap with Yoast SEO:

  1. Install and Activate Yoast SEO Plugin: You can download the plugin from the WordPress repository or directly install it from your WordPress dashboard by navigating to "Plugins" > "Add New", then search for "Yoast SEO", and click "Install Now". After installing, activate the plugin.

  2. Enable the XML Sitemap Functionality: Once the plugin is active, go to "SEO" > "General" on your WordPress dashboard, then navigate to the "Features" tab. Find the "XML Sitemaps" option and ensure it's toggled to "On". This enables Yoast to automatically create a sitemap for you.

  3. Check Your Sitemap: You can check your sitemap by adding /sitemap_index.xml to your domain URL, like so: This should display all the sitemaps Yoast has created for your site.

  4. Configure Sitemap Settings: If you wish to configure which content types appear in your sitemap, navigate to "SEO" > "Search Appearance", and then choose the appropriate content type (e.g., "Posts", "Pages", "Media", etc.). Each section will have an option called “Show in search results?”. If it's set to "Yes", the content type will be included in your sitemap.

Here's a code snippet to add a custom sitemap to Yoast's sitemap index programmatically:

add_action( 'init', 'add_custom_sitemap' ); function add_custom_sitemap(){ $GLOBALS['wpseo_sitemaps']->register_sitemap( 'my_custom_sitemap', 'create_my_custom_sitemap' ); } function create_my_custom_sitemap(){ $sitemap = array(); // Add your custom URLs to the $sitemap array.... // Output your sitemap: header('Content-Type: text/xml'); echo '<?xml version="1.0" encoding="UTF-8"?>'. "\n"; echo '<urlset xmlns="">' . "\n"; foreach ($sitemap as $url){ echo '<url>' . "\n"; echo '<loc>' . htmlspecialchars($url) . '</loc>' . "\n"; echo '</url>' . "\n"; } echo '</urlset>'; }

Remember, it's important to periodically check your sitemap to ensure that it correctly reflects the structure and content of your site.

Other Common Sitemap Questions (and Answers)

© ContentForest™ 2012 - 2024