-
Notifications
You must be signed in to change notification settings - Fork 907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing a CPT from the sitemap but leaving the CPT Archive page in the sitemap does not work #11391
Comments
Shouldn't we just hide/remove the settings for the CPTs archive when the CPT is set to not show in search results, @jdevalk? |
@tacoverdo I'm not sure that's the best approach. It's related to #11225. It's possible that someone want to set all posts to "noindex" by global settings (if there are a lot of posts) and manually set "index" to few posts including archive page. In this case there is inconsistency between sitemap and "indexable" posts (search engines should have not problems finding and indexing them, but they may show warnings). I'll create PR which will fix it in next weeks. Similar issues (which could be fixed): #11225, #9953, #10312. Maybe it's possible to merge all of them into one issue. |
No there are valid use cases where you'd want the archive indexed, looking forward to that PR @stodorovic :) |
Hi, any news about this issue, is it fixed now please? |
It isn't fixed. I've created couple PRs related to sitemaps in meantime and I didn't find time for this issue. I'll try to create PR soon (it could be my next PR related to sitemaps). |
Just found this issue after experiencing the exact problem myself with a CPT. In my case, I deliberately want to not index the single CPT posts, but I also deliberately do want to index (and include in sitemap) the CPT archive page. Therefore I definitely would not like to see the CPT archive setting hidden, as suggested by tacoverdo above. ;) I'm glad you're working on a fix for this! |
+1 for this. I need to include a CPT Archive, but exclude all the Single Posts. Had to switch to a different Sitemap generator until this is fixed :( |
Almost 6 months since this issue has been reported, any news about a fix? |
Any news please? |
This issue currently has no priority and is not being worked on from within our development team. We do welcome any community patches that would fix this though. Once this is being picked up, this thread will get notified. |
Hi @Djennez, is it likely that this issue will be picked up at some point in the future? Or are you saying that it's a "won't fix" issue for your team? @stodorovic had mentioned, back in January, that he would try and create a PR for it soon. :) As it's effectively a bug of sorts, and @jdevalk has commented that there are valid use-cases for this scenario, then surely it needs to be fixed/implimented? :) |
This bug is incredible, the only way I found to solve the problem is to set each post as noindex from the advanced yoast settings of the single post. |
@Djennez It's been a while. Will this issue be fixed anytime in the future? |
I don't believe this has been planned in any of the future projects yet. @JessieHenkes can this possibly be included in the Indexable sitemap overhaul? Or is it too much out of scope for that? |
@JessieHenkes Any follow up on this? |
As soon as it's worked on / fixed, you'll see this thread being updated. |
@Djennez Sorry. I don't mean to bother anyone. I know you have lives and such. :) |
@studioavanti @shikkaba @GermanKiwi I've recently stumbled into this bug and thanks to some new filters in Yoast SEO was able to come up with a quick solution that helped me. Sharing it with you (just change $post_type value to whatever post type archive you want to add): https://wordpressify.ru/2020/12/dobavlenie-svoej-ssylki-v-sitemap-stranits-yoast-seo/ |
@acerus thanks so much for providing that function! It works well, and in the absence of an official fix from the developers, this is a really good workaround. 👍 I've actually made a couple of small adjustments to the function, and I'll paste my version of it below. In short: I noticed that your version was outputting the date in the page-sitemap.xml file in this format: 2020-12-20 05:16 Whereas the dates for every other page in this file use the following format: 2020-12-20T04:16:44+00:00 So in order to get this format, I've tweaked your function to look like this:
Key things I changed:
Hope that's helpful! |
Thank you, those are actually very helpful adjustments! |
@acerus , @GermanKiwi what if I need to add several CPT archive pages to my sitemap.xml - do I need to copy/paste our code several times or may be I can just use commas, separating my post_type titles? |
@MaxDarklighter that's a good question. My suspicion is that you may need to make additional copies of the function - one per CPT, with each function having a unique name of course. However, it's entirely possible I'm wrong, and hopefully someone with deeper knowledge of functions could give a more authoritative answer here. At the very least, it will certainly work fine to use multiple functions. It won't break anything. I just don't know if it's the most efficient way to do it. |
@GermanKiwi just 10min ago I tried to do it and I got critical error on my site. But no worries - I deleted all copies of "function add_archive_URL()" and it's ok now :) |
@MaxDarklighter if you're adding more than one copy of the function, it's important that each copy has a unique name, which is mentioned in both the 1st line (beginning with "function") and last line (beginning with "add_filter"). So for example:
|
Creating multiple functions didn't' work for me. It only took notice of the last one (despite varying IDs). In the end I created Pages with the same Slug as the Archive Pages and they appeared in the index but organically redirected to the correct page. |
I needed a solution for multiple languages in WPML so I've modified this code for that and am sharing in case anyone else needs it (I'm not sure why the insert code feature isn't wanting to work for me): `
} |
"Show [CPT-name] in search results?" -> Off With the above settings, it would be expected to see the archive page in the sitemap. This is currently not the case. I can see the 'robots' meta tag in the head of the archive page change from 'index' to 'noindex' when changing the second setting, fortunately. |
The code by @GermanKiwi wasn't working for me. The following does. Perhaps this will help someone in 2024. Note, I did mine for a CPT called project, you'll need to change it for your needs. Basically, all I'm doing is filtering into the WHERE clause in the SQL call the plugin makes and making it so that it returns no results. That way, it will only show the archive page and no single posts in the sitemap. `<?php
}, 10, 2 ); |
Please give us a description of what happened.
Setting a custom post type not to be indexed will remove it from the sitemap and add a "noindex" to all posts in the CPT.
The Yoast plugin has the option of treating the CPT Archive page separately, by letting you index the archive pages. However, selecting "Yes" in "Show CPT Archive in search results" will not add the CPT Archive to the sitemap, even if the pages do not get a "noindex".
Please describe what you expected to happen and why.
I expected that the CPT Archive page would appear in the sitemap.
How can we reproduce this behavior?
1.Create a Custom Post Type.
2.Go to SEO -> Search Appearance -> Content Types
3.Set the Custom Post Type not to appear in search engines.
4.Set the CPT Archive pages to appear in search engines.
5.Verify that the CPT Archive pages are not in the sitemap.
Technical info
WordPress version: 4.9.8
Yoast SEO version: 9.0.1
Tested with theme: TwentySeventeen
The text was updated successfully, but these errors were encountered: