Open grappler opened 3 years ago
I have run in this problem as well, and I am looking for a solution to solve this with the native sitemap feature.
This works for me (this will exclude all pages which have a new URL set up via the "Page links to" plugin from the sitemap):
add_filter(
'wp_sitemaps_posts_query_args',
function( $args, $post_type ) {
if ( 'page' !== $post_type ) {
return $args;
}
$args['meta_query'] = isset( $args['meta_query'] ) ? $args['meta_query'] : array();
$args['meta_query'][] = array(
'key' => '_links_to',
'compare' => 'NOT EXISTS',
);
return $args;
},
10,
2
);
It looks like these are now automatically excluded from the sitemap, at least in Yoast.
However, I'm looking for the exact opposite of this: I'd like to show the "Page Links To" URLs in the sitemap. How would I go about that, please?
As posts with links point to other pages or other sites, the links should not be included in the sitemap. Here is how I solved for Yoast SEO. This is more for information if anyone else is looking into this then a feature request. Though doing something like this for the new default WP sitemap may be an idea.