Add additional/external XML sitemaps to the XML sitemap index
Misc:
Alter the URL of an entry
Alter the number of sitemap entries
Filter the urlset element.
`/**
Excludes posts from XML sitemaps.
@return array The IDs of posts to exclude.
*/
function exclude_posts_from_xml_sitemaps() {
return [ 13 ];
}
add_filter( 'sm_exclude_from_sitemap_by_post_ids', 'exclude_posts_from_xml_sitemaps' );
/* Exclude a post types from XML sitemaps.
@return array The slugs of post types to exclude.
*/
function sm_sitemap_exclude_post_types() {
return [ 'news' ];
}
add_filter( 'sm_sitemap_exclude_post_types', 'sm_sitemap_exclude_post_types' );
/* Exclude a post types from XML sitemaps.
@return array The slugs of post types to exclude.
*/
function sm_sitemap_exclude_taxonomy() {
return [ 'news-category', 'genre' ];
}
add_filter( 'sm_sitemap_exclude_taxonomy', 'sm_sitemap_exclude_taxonomy' );
/* Excludes author with ID of 5 from author sitemaps.
@param array $users Array of User objects to filter through.
@return array The remaining authors.
*/
function sm_sitemap_exclude_author( $users ) {
return array_filter( $users, function( $user ) {
if ( $user->ID === '1' ) {
return false;
}
return true;
} );
}
add_filter( 'sm_sitemap_exclude_author', 'sm_sitemap_exclude_author' );
/* Excludes terms with ID of 9 and 10 from terms sitemaps.
@param array $terms Array of term IDs already excluded.
@return array The terms to exclude.
*/
function sm_exclude_from_sitemap_by_term_ids( $terms ) {
return [ 9, 10 ];
}
add_filter( 'sm_exclude_from_sitemap_by_term_ids', 'sm_exclude_from_sitemap_by_term_ids' );
/* Include a post types to XML sitemaps.
@return array The slugs of post types to include.
*/
function sm_sitemap_include_post_type() {
return [ 'news' ];
}
add_filter( 'sm_sitemap_include_post_type', 'sm_sitemap_include_post_type' );
/* 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 sm_sitemap_index( $sitemap_custom_items ) {
$sitemap_custom_items[] = [
'title' => 'external-sitemap',
'modified' => '2024-05-31 13:58:13'
];
/* Alters the URL structure for an example custom post type.
@param string $url The URL to modify.
@param WP_Post $post The post object.
@return string The modified URL.
/
function sm_xml_sitemap_post_url( $url, $post ) {
if ( $post->post_type === 'news' ) {
return \str_replace( 'news', 'news-replaced', $url );
}
/* Alters the number of entries in each XML sitemap.
@return integer The maximum entries per sitemap.
*/
function sm_sitemap_entries_per_page() {
return 10;
}
add_filter( 'sm_sitemap_entries_per_page', 'sm_sitemap_entries_per_page' );
/* Filters the urlset for all sitemaps.
@param string $urlset The output for the sitemap's urlset.
*/
function sm_sitemap_urlset( $urlset ) {
return str_replace( '>', ' xmlns:xhtml="http://www.w3.org/1999/xhtml">', $urlset );
}
add_filter( 'sm_sitemap_urlset', 'sm_sitemap_urlset', 10, 1 );`
Added filters ащк:
Excluding:
Adding:
Misc:
`/**
/* Exclude a post types from XML sitemaps. @return array The slugs of post types to exclude. */ function sm_sitemap_exclude_post_types() { return [ 'news' ]; } add_filter( 'sm_sitemap_exclude_post_types', 'sm_sitemap_exclude_post_types' );
/* Exclude a post types from XML sitemaps. @return array The slugs of post types to exclude. */ function sm_sitemap_exclude_taxonomy() { return [ 'news-category', 'genre' ]; } add_filter( 'sm_sitemap_exclude_taxonomy', 'sm_sitemap_exclude_taxonomy' );
/* Excludes author with ID of 5 from author sitemaps. @param array $users Array of User objects to filter through. @return array The remaining authors. */ function sm_sitemap_exclude_author( $users ) { return array_filter( $users, function( $user ) { if ( $user->ID === '1' ) { return false; } return true; } ); } add_filter( 'sm_sitemap_exclude_author', 'sm_sitemap_exclude_author' );
/* Excludes terms with ID of 9 and 10 from terms sitemaps. @param array $terms Array of term IDs already excluded. @return array The terms to exclude. */ function sm_exclude_from_sitemap_by_term_ids( $terms ) { return [ 9, 10 ]; } add_filter( 'sm_exclude_from_sitemap_by_term_ids', 'sm_exclude_from_sitemap_by_term_ids' );
/* Include a post types to XML sitemaps. @return array The slugs of post types to include. */ function sm_sitemap_include_post_type() { return [ 'news' ]; } add_filter( 'sm_sitemap_include_post_type', 'sm_sitemap_include_post_type' );
/* 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 sm_sitemap_index( $sitemap_custom_items ) { $sitemap_custom_items[] = [ 'title' => 'external-sitemap', 'modified' => '2024-05-31 13:58:13' ];
$sitemap_custom_items[] = [ 'title' => 'external-sitemap-2', 'modified' => '2024-06-30 13:58:13' ];
return $sitemap_custom_items; } add_filter( 'sm_sitemap_index', 'sm_sitemap_index' );
/* Alters the URL structure for an example custom post type. @param string $url The URL to modify. @param WP_Post $post The post object. @return string The modified URL. / function sm_xml_sitemap_post_url( $url, $post ) { if ( $post->post_type === 'news' ) { return \str_replace( 'news', 'news-replaced', $url ); }
return $url; } add_filter( 'sm_xml_sitemap_post_url', 'sm_xml_sitemap_post_url', 10, 2 );
/* Alters the number of entries in each XML sitemap. @return integer The maximum entries per sitemap. */ function sm_sitemap_entries_per_page() { return 10; } add_filter( 'sm_sitemap_entries_per_page', 'sm_sitemap_entries_per_page' );
/* Filters the
urlset
for all sitemaps. @param string $urlset The output for the sitemap'surlset
. */ function sm_sitemap_urlset( $urlset ) { return str_replace( '>', ' xmlns:xhtml="http://www.w3.org/1999/xhtml">', $urlset ); } add_filter( 'sm_sitemap_urlset', 'sm_sitemap_urlset', 10, 1 );`