php Yoast SEO站点地图的过滤器和示例代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Yoast SEO站点地图的过滤器和示例代码相关的知识,希望对你有一定的参考价值。

<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
 
 /* Create Custom Yoast Sitemap
  * Credit: Unknown
  * Last Tested: Unknown
  *********
  * HOW TO USE
  * Replace TYPE with your custom type
  */

add_action( 'init', 'enable_custom_sitemap' );

function enable_custom_sitemap() {
    global $wpseo_sitemaps;
    if ( isset( $wpseo_sitemaps ) && ! empty ( $wpseo_sitemaps ) ) {
        $wpseo_sitemaps->register_sitemap( 'TYPE', 'create_TYPE_sitemap' );
        }
     }
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/

/* Add External Sitemap to Yoast Sitemap Index
 * Credit: Paul https://wordpress.org/support/users/paulmighty/
 * Last Tested: Aug 25 2017 using Yoast SEO 5.3.2 on WordPress 4.8.1
 *********
 * This code adds two external sitemaps and must be modified before using.
 * Replace http://www.example.com/external-sitemap-#.xml
   with your external sitemap URL.
 * Replace 2017-05-22T23:12:27+00:00
   with the time and date your external sitemap was last updated.
   Format: yyyy-MM-dd'T'HH:mm:ssZ
 * If you have more/less sitemaps, add/remove the additional section.
 *********
 * Please note that changes will be applied upon next sitemap update.
 * To manually refresh the sitemap, please disable and enable the sitemaps.
 */

add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );

function add_sitemap_custom_items() {
   $sitemap_custom_items = '
<sitemap>
<loc>http://www.example.com/external-sitemap-1.xml</loc>
<lastmod>2017-05-22T23:12:27+00:00</lastmod>
</sitemap>';
   
/* Add Additional Sitemap
 * This section can be removed or reused as needed
 */
  $sitemap_custom_items .= '
<sitemap>
<loc>http://www.example.com/external-sitemap-2.xml</loc>
<lastmod>2017-05-22T23:12:27+00:00</lastmod>
</sitemap>';

/* DO NOT REMOVE ANYTHING BELOW THIS LINE
 * Send the information to Yoast SEO
 */
return $sitemap_custom_items;

}
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/

/* Change the number of entries per sitemap
 * Credit: Yoast Team
 * Last Tested: Oct 17 2018 using Yoast SEO 8.4 on WordPress 4.9.8
 *********
 */
 
add_filter( 'wpseo_sitemap_entries_per_page', 'max_entries_per_sitemap' );

 function max_entries_per_sitemap() {
    return 10;
}

以上是关于php Yoast SEO站点地图的过滤器和示例代码的主要内容,如果未能解决你的问题,请参考以下文章

php 将IDX站点地图添加到Yoast SEO站点地图

php Yoast SEO | HTML站点地图

php Wordpress yoast seo插件,为自定义URL生成自定义站点地图

php Wordpress yoast seo插件,为自定义URL生成自定义站点地图

php Yoast SEO机器人或WP robots.txt的过滤器和示例代码

使用Yoast SEO提交Sitemap