Excluding Posts from the sitemap

Need help with this?
Purchase All in One SEO Pack Pro to get dedicated support from us.

Buy Now

The aioseop_sitemap_post_filter filter hook.


apply_filters( 'aioseop_sitemap_post_filter', $posts, $args );

This filter can be used to filter the posts that are included in the sitemap.

Parameters (1)

0. $posts (array)
the posts that are included in the current sitemap.
1. $args(array)
additional context info, such as the post type.


The code example below can be used to exclude posts with a given ID from the sitemap:

add_filter( 'aiosp_sitemap_post_filter', 'exclude_posts_from_sitemap', 10, 2 );

function exclude_posts_from_sitemap( $posts, $args ) {
	$excluded_post_ids = array( '16', '22', '82');

	$filtered_posts = array();
	foreach( $posts as $post) {
		if( ! in_array($post->ID, $excluded_post_ids)) {
			array_push($filtered_posts, $post);
	return $filtered_posts;

For instructions on how to use this code, please refer to our FAQ here.

  • Was this helpful ?
  • YesNo