专注分享优质资源

WP博客修改Sitemap名称操作步骤WordPress

爱留 无分类
众所周知WordPress默认的站点地图名称为wp-sitemap.xml,如果需要将默认名称wp-sitemap.xml修改为sitemap.xml该如何操作呢?

具体的操作步骤如下:

第一步:将以下代码添加到当前主题的functions.php文件中即可,文件路径:/wp-content/themes/主题目录/functions.php

add_action( 'init', 'add_new_url_main_sitemap' );
add_filter( 'home_url', 'fix_wp_sitemap_url', 11, 2 );
function add_new_url_main_sitemap() {
add_rewrite_rule( '^sitemap\.xml$', 'index.php?sitemap=index', 'top' );
}
function fix_wp_sitemap_url( $url, $path ) {
if ( '/wp-sitemap.xml' === $path ) {
return str_replace( '/wp-sitemap.xml', '/sitemap.xml', $url );
}
return $url;
}
 第二步:进入网站后台点击【设置】-【固定链接】 -【保存更改】更新即可
评论列表