Hands-on Tutorial: How to Customize Rank Math XML Sitemap Path by Keywords

exist WordPress (used form a nominal expression) SEO Fields.Rank Math Undoubtedly one of the most powerful and flexible plugins available. Typically.Rank Math will be generated by default with the name sitemap_index.xml of the site map.

While this meets most of the needs, out ofsafety(Hide commonly used plugin paths),branding(using specific keywords) orAvoid conflicts with other pluginsFor example, you may want to change the URL of your sitemap to a more personalized name, such as cool-map.xml maybe site-index.xmlThe

Today, we're going to show you by hand how to accomplish this advanced operation with simple code.

图片[1]-别再用默认路径了!手把手教你修改 Rank Math 站点地图 URL 提升安全性

Why should I change the default sitemap URL?

Before we dive into the practicalities, let's take a look at what this has to offer:

  1. Enhancing Security: The default path is easily targeted by automated crawlers, and modifying the path reduces the risk of being maliciously scanned.
  2. brand consistency: You can incorporate keywords into URL in it to make it look more in line with the overall naming convention of the site.
  3. conflict resolution: If your server or another plugin takes up the default sitemap_index.xml, custom paths are the only way out.

preliminary

Before you start, make sure:

  • Your site has installed and enabled Rank Math SEO Plug-ins.
  • It is recommended that the site be firstbacking up(Although this is routine, good habits save lives).
  • If you're not comfortable directly modifying functions.phpRecommended Installation Code Snippets Plug-ins.
图片[2]-别再用默认路径了!手把手教你修改 Rank Math 站点地图 URL 提升安全性

Core step: customizing the sitemap name through code

Rank Math doesn't provide a "one-click modification" textbox in the backend UI, but it does reserve a very powerful Filter Interface.

Step 1: Add custom filter code

You need to add the following code to the theme's functions.php file, or via the Code Snippets plugin:

PHP

/**
 * Change the index filename of the Rank Math sitemap
 */
add_filter( 'rank_math/sitemap/index_name', function( $name ) {
    return 'your-keyword-sitemap'; // enter the keyword you want here without the .xml
}).

Attention: Please change the code in the your-keyword-sitemap Replace it with the keyword of your choice (e.g. mysite-map).

图片[3]-别再用默认路径了!手把手教你修改 Rank Math 站点地图 URL 提升安全性

Step 2: Refresh WordPress Fixed Links (Key Step)

After adding the code, you'll notice that direct access to the new path will show you a 404. This is because WordPress routing rules haven't been updated yet.

  • Log in to the WordPress backend.
  • Navigate to Settings > PermalinksThe
图片[4]-别再用默认路径了!手把手教你修改 Rank Math 站点地图 URL 提升安全性
  • No need to change anythingto scroll directly to the bottom of the page and click on the "Save changes"The
  • This step forces WordPress to re-read the routing table to make your new sitemap path effective.
图片[5]-别再用默认路径了!手把手教你修改 Rank Math 站点地图 URL 提升安全性

How do I verify that the changes were successful?

Once the modification is complete, you can verify it by following the three steps below:

1. Direct access to the new URL

Enter it in your browser:https://yourdomain.com/your-keyword-sitemap.xmlIf you can see Rank Math's standard site map interface, you're done. If you can see Rank Math's standard sitemap interface, you're done.

图片[6]-别再用默认路径了!手把手教你修改 Rank Math 站点地图 URL 提升安全性

2. Check Robots.txt

Rank Math will automatically update your robots.txt file that announces the new map location to search engines. You can visit the yourdomain.com/robots.txt ferret out Sitemap. Whether the instruction has pointed to the new address.

图片[7]-别再用默认路径了!手把手教你修改 Rank Math 站点地图 URL 提升安全性

3. Update in Google Search Console

This is the most important step.

  1. go into Google Search ConsoleThe
  2. Click on the left menu of the "Sitemaps" (site maps)The
  3. Submit your brand-new sitemap URL and remove the old sitemap_index.xmlThe
图片[8]-别再用默认路径了!手把手教你修改 Rank Math 站点地图 URL 提升安全性

Advancement Notes

  • Don't forget the .xml at the end: Although we don't write the extension in the code, it must be added when accessing the .xmlThe
  • Redirect to old address: To be on the safe side, it is recommended to use Rank Math's own Redirections function, which will be the old sitemap_index.xml Permanent redirection (301) to a new address, to prevent search engine crawlers "lost".

summarize

Changing the Rank Math sitemap position is not complicated and requires a simple piece of filter code and a refresh of the fixed links. This kind of fine-tuning, although it's not very easy for the SEO RankingThere's no direct bludgeoning damage, but it reflects your extreme control over the details of your website.


Contact Us
Can't read the tutorial? Contact us for a free answer! Free help for personal, small business sites!
客服微信
Customer Service
Tel: 020-2206-9892
QQ咨询:1025174874
(iii) E-mail: [email protected]
Working hours: Monday to Friday, 9:30-18:30, holidays off
© Reprint statement
本文作者:托尼屎大颗
THE END
If you like it, support it.
kudos73 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments