如何给Yoast增加自定义Sitemap?

为了平时使用,我整理了一个HTML版本的在线工具方便我自己使用,同时希望搜索引擎收录,希望对其他朋友有帮助。

Yoast的sitemap功能如何加上这些地图呢?

生成xml文件

使用XML Sitemaps Generato在线生成,放到在线工具的根目录。

添加xml到yost sitemap

参考官方api,在主题functions.php文件中或者使用Code Snippets插件添加自定义代码:

/**
 * Writes additional/custom XML sitemap strings to the XML sitemap index.
 *
 * @param string $sitemap_custom_items XML describing one or more custom sitemaps.
 *
 * @return string The XML sitemap index with the additional XML.
 */
function add_sitemap_custom_items( $sitemap_custom_items ) {
    $sitemap_custom_items .= '
<sitemap>
<loc>https://wpmore.cn/resources/sitemap.xml</loc>
<lastmod>2022-02-27T23:16:40+00:00</lastmod>
</sitemap>';
    return $sitemap_custom_items;
}

add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );

Writes additional/custom XML sitemap strings to the XML sitemap index
然后查看地图xml文件,就可以看到多出了sitemap,已经成功添加上了。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注