Title: Cannot use sitemap filter (PHP)
Last modified: April 13, 2017

---

# Cannot use sitemap filter (PHP)

 *  Resolved [Jorge Raigoza](https://wordpress.org/support/users/forfe15/)
 * (@forfe15)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/cannot-use-sitemap-filter-php/)
 * Hi,
 * I am trying to filter the results generated on my page-sitemap.xml. I am aware
   I can use the option **_Posts to exclude_** under **_SEO_** > **_XML_** > **_Sitemaps_**
   > **_Excluded Posts_**. However, this option only excludes the noted items and
   not their children.
 * Based on the information provided [here](https://kb.yoast.com/kb/how-to-customize-the-sitemap-index/?utm_source=support&utm_medium=forum&utm_campaign=support-link#exclude_taxonomy),
   I tried adding the code to my Functions.php file, but it does not get “called”.
 * During my testing, I removed all the code I created and left only **_return true;_**.
   If I am not mistaking, this should have left me with no items on the page-sitemap.
   xml “page”, but nothing changes….
 * >  function sitemap_exclude_taxonomy( $value, $taxonomy ) {
   >  return true; }
   > add_filter( ‘wpseo_sitemap_exclude_taxonomy’, ‘sitemap_exclude_taxonomy’, 10,
   > 2 );
 * At some point, I though this issue could be related to my WP setup; we are using
   a child theme. So, I edited the main theme’s Functions.php to add the same code
   and see if anything changes, but no luck.
 * Am I missing a step somewhere?
    -  This topic was modified 9 years, 1 month ago by [Jorge Raigoza](https://wordpress.org/support/users/forfe15/).
    -  This topic was modified 9 years, 1 month ago by [Jorge Raigoza](https://wordpress.org/support/users/forfe15/).
    -  This topic was modified 9 years, 1 month ago by [Jorge Raigoza](https://wordpress.org/support/users/forfe15/).
      Reason: misspell

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Jorge Raigoza](https://wordpress.org/support/users/forfe15/)
 * (@forfe15)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/cannot-use-sitemap-filter-php/#post-9025288)
 * Never mind. I misread the article. I always get confuse with the word **Taxonomy**:
    - Category
    - Tag
    - Link Category
    - Post Format
    - Custom Taxonomies
 * Basically, I was trying to filter posts and pages using their ID instead of a
   taxonomy slug.
 * Is there any way to filter per post ID using PHP?
 *  Thread Starter [Jorge Raigoza](https://wordpress.org/support/users/forfe15/)
 * (@forfe15)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/cannot-use-sitemap-filter-php/#post-9025391)
 * Never mind x2.
 * The correct filter is **wpseo_sitemap_entry**. This filter applies to all post
   and page elements.
 * Return the **$url** parameter for the elements that you want. For the elements
   that you do not want, return **”** (_EMPTY_).
 *     ```
       function sitemap_exclude_post( $url, $type, $post ) {
   
       	if ( $post->ID === 1 ) {
       		// Exclude
       		return '';
       	}
   
       	return $url;
       }
       add_filter( 'wpseo_sitemap_entry', 'sitemap_exclude_post', 1, 3 );
       ```
   
    -  This reply was modified 9 years, 1 month ago by [Jorge Raigoza](https://wordpress.org/support/users/forfe15/).
      Reason: grammar and styling

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Cannot use sitemap filter (PHP)’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-seo/assets/icon-256x256.gif?rev=3419908)
 * [Yoast SEO - Advanced SEO with real-time guidance and built-in AI](https://wordpress.org/plugins/wordpress-seo/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-seo/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-seo/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-seo/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-seo/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-seo/reviews/)

## Tags

 * [sitemap](https://wordpress.org/support/topic-tag/sitemap/)

 * 2 replies
 * 1 participant
 * Last reply from: [Jorge Raigoza](https://wordpress.org/support/users/forfe15/)
 * Last activity: [9 years, 1 month ago](https://wordpress.org/support/topic/cannot-use-sitemap-filter-php/#post-9025391)
 * Status: resolved