• Resolved gauthierlofti

    (@gauthierlofti)


    Hi there!

    I hope you are all well. I come here because I have an issue with the SEO Framework plug in.

    So my goal is the following: I want to remove certain urls from my sitemap to put them in a dedicated sitemap (added directly in a static file on my website server)

    My issue is the following:

    • Following the documentation of the SEO Framework, the way to do that is to mark the page as noindex
    • Once doing this, if we check the body of the page, a <meta>tag appears as follow <meta name="robots" content="noindex,max-snippet:-1,max-image-preview:standard,max-video-preview:-1">.
    • With this meta tag applied then my page (even if it does not appear on the sitemap) will have no chance at all to be indexed and I definitely need to index it.

    My question is then, how can I remove/exclude the urls I want from the generated sitemap without having this meta tag applied to the body of page?

    I’ve been looking into the plug in settings about exclusion but it appears that I can’t apply the exclusion to a specific category (also, I might not be technical enough on php to handle it myself).

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    Thank you 🙂

    I’m unsure why you would go through the hassle of maintaining another sitemap.

    Nevertheless, you need to use a filter to remove indexable posts from the sitemap.

    When you have a standard list of IDs you wish to exclude, the best thing is to forward all those IDs at once via the_seo_framework_sitemap_exclude_ids.

    I’m not sure what you mean by “apply the exclusion to a specific category,” is it all posts in the category, the category itself, or something else?

    Considering you wish to exclude all posts with a specific category, this snippet should help:

    add_filter(
    	'the_seo_framework_sitemap_exclude_ids',
    	function( $ids ) {
    
    		$my_exclude_ids = get_posts( [
    			'post_type' => 'post',
    			'fields'    => 'ids',
    			'tax_query' => [
    				[
    					'taxonomy' => 'category',
    					'field'    => 'term_id',
    					'terms'    => 42,
    				],
    			],
    		] );
    
    		return array_merge( $ids, $my_exclude_ids );
    	}
    );

    In that snippet, you see the number 42 — you should change this to the ID of your category. When you edit a category, you can see in your browser’s URL bar tag_ID=42, which you should take the number from.

    (Where do I place filters?)

    I hope this helps! Cheers 🙂

    Thread Starter gauthierlofti

    (@gauthierlofti)

    Hi thank you a lot for the quick answer.

    Helps a lot. The reason I want to have a static sitemap is because for now, I don’t have the ability to organise my sitemaps as I want. And as I plan to add several urls I need a solution that allows me to organise these sitemaps as I want (into sitemaps of sitemaps for example etc.)

    The post_type I am targeting is pages and it seems that the filter does not work on that, is that correct?

    I’ve tried to adapt your snippet to fit to the pages object and added the filter via the CodeSnippet plugin without success.

    add_filter(
    	'the_seo_framework_sitemap_exclude_ids',
    	function( $ids ) {
    
    		$my_exclude_ids = new WP_Query( array(
    			'post_type' => 'page',
    			'tax_query' => array(
    				array(
    					'taxonomy' => 'post_Tag',
    					'field'    => 'tag_id',
    					'terms'    => 179,
    				),
    			),
    		) );
    
    		return array_merge( $ids, $my_exclude_ids );
    	}
    );

    Seems that the filter is not applied, even when setting the highest prio. Any idea why?

    Thank you again for your help,

    Gauthier

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Gauthier,

    Sitemaps pose no benefit to ranking, they only speed up indexing. Generally, visitors never see the sitemap, only search engines. I firmly believe that optimizing the sitemap beyond the capabilities of The SEO Framework (or WordPress) is futile: https://tsf.fyi/kb/sitemap.

    I’m not sure why you rewrote my tested code. I marked all issues in // comments below:

    add_filter(
    	'the_seo_framework_sitemap_exclude_ids',
    	function( $ids ) {
    
    		$my_exclude_ids = new WP_Query( array( // Why have you change this? I tested my code before I sent it to you.
    			'post_type' => 'page', // Post type "page" doesn't have taxonomies by default, so a 'tax_query' won't work.
    			'tax_query' => array( // Why use an archaic form of array() instead of the easier to read and write []?
    				array(
    					'taxonomy' => 'post_Tag', // should be post_tag. Everything is case-sensitive. But you wrote "category" in your initial request...? post_tag are also for post, not page.
    					'field'    => 'tag_id',   // should be term_id
    					'terms'    => 179,
    				),
    			),
    		) );
    
    		return array_merge( $ids, $my_exclude_ids );
    	}
    );
    Thread Starter gauthierlofti

    (@gauthierlofti)

    Hi @cybr

    My issue is exactly on indexing, and I want to speed up this process.

    The reason I rewrote part of the code is because as you can imagine, when I tried it, it did not work. Two main reasons

    • first, indeed I’m using a tag instead of a category (indeed, it wasn’t in my initial message)
    • secondly, as you can see in my code, the post type I’m targeting with this filter is the page post type not the post (which indeed would have been easier). So after some research I found out that, as you mention, the page post type does not have taxonomies, forcing me to use the WP_query function which allows the use of the tax_query.

    I know that using Pages like this is quite unusual. If you think it would not be possible to filter out these pages with a specific category or tag (the difference does not seem to be too hard to handle) don’t hesitate to let me know.

    Thanks again for the help & advices you already provided.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi again!

    How are the pages and post tags related, and how is this achieved? Once we know that, we can figure out a way to exclude them.

    Still, if you have indexing issues, it seldom is because of the sitemap but a problem with the website. Think of faulty robots-tags, canonical URLs, interlinking, thin content, spam, “manual actions” (penalties), etc.

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

The topic ‘Remove specific urls from sitemap’ is closed to new replies.