• Resolved Jorge Raigoza

    (@forfe15)


    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, 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.
    • This topic was modified 9 years, 1 month ago by Jorge Raigoza.
    • This topic was modified 9 years, 1 month ago by Jorge Raigoza. Reason: misspell
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Jorge Raigoza

    (@forfe15)

    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

    (@forfe15)

    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. 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.