Skip to content
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

Open
rmarcano opened this issue Oct 23, 2018 · 20 comments

Comments

@rmarcano
Copy link

@rmarcano rmarcano commented Oct 23, 2018

  • I've read and understood the contribution guidelines.
  • I've searched for any related issues and avoided creating a duplicate issue.

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

cptarchive

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

@tacoverdo
Copy link
Member

@tacoverdo tacoverdo commented Oct 30, 2018

Shouldn't we just hide/remove the settings for the CPTs archive when the CPT is set to not show in search results, @jdevalk?

@stodorovic
Copy link
Contributor

@stodorovic stodorovic commented Oct 31, 2018

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

@jdevalk
Copy link
Member

@jdevalk jdevalk commented Oct 31, 2018

No there are valid use cases where you'd want the archive indexed, looking forward to that PR @stodorovic :)

@studioavanti
Copy link

@studioavanti studioavanti commented Jan 2, 2019

Hi, any news about this issue, is it fixed now please?

@stodorovic
Copy link
Contributor

@stodorovic stodorovic commented Jan 3, 2019

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

@GermanKiwi
Copy link

@GermanKiwi GermanKiwi commented Jan 10, 2019

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!

@ChrisStanyon
Copy link

@ChrisStanyon ChrisStanyon commented Feb 4, 2019

+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 :(

@studioavanti
Copy link

@studioavanti studioavanti commented Apr 16, 2019

Almost 6 months since this issue has been reported, any news about a fix?

@studioavanti
Copy link

@studioavanti studioavanti commented Jun 13, 2019

Any news please?

@Djennez
Copy link
Member

@Djennez Djennez commented Jun 13, 2019

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.

@GermanKiwi
Copy link

@GermanKiwi GermanKiwi commented Jun 14, 2019

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? :)

@stodorovic stodorovic mentioned this issue Jan 2, 2020
4 of 11 tasks complete
@simonemanfre
Copy link

@simonemanfre simonemanfre commented Apr 2, 2020

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.
Fortunately I have this problem in a post type with 10 posts, but if I had 1000? I would be forced to change the plugin

@shikkaba
Copy link

@shikkaba shikkaba commented Jun 8, 2020

@Djennez It's been a while. Will this issue be fixed anytime in the future?

@Djennez
Copy link
Member

@Djennez Djennez commented Jun 8, 2020

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?

@shikkaba
Copy link

@shikkaba shikkaba commented Jul 19, 2020

@JessieHenkes Any follow up on this?

@Djennez
Copy link
Member

@Djennez Djennez commented Jul 20, 2020

As soon as it's worked on / fixed, you'll see this thread being updated.

@shikkaba
Copy link

@shikkaba shikkaba commented Aug 2, 2020

@Djennez Sorry. I don't mean to bother anyone. I know you have lives and such. :)
I was just not sure how to pursue it as this issue was opened in 2018, and it would be awesome to know if it was at least on the radar in some way.

@acerus
Copy link

@acerus acerus commented Dec 15, 2020

@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/

@GermanKiwi
Copy link

@GermanKiwi GermanKiwi commented Dec 21, 2020

@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:

function add_archive_URL() {
	$post_type = 'my_custom_post_type';
	$archive_url = get_post_type_archive_link( $post_type );

	$args = [
		'posts_per_page'         => 1,
		'post_type'              => $post_type,
		'orderby'                => 'modified',
		'order'                  => 'DESC',
		'no_found_rows'          => true,
		'update_post_meta_cache' => false,
		'update_post_term_cache' => false,
		'fields'                 => 'ids',
		'cache_results'          => true
	];

	$latest = new WP_Query( $args );

	while ( $latest->have_posts() ) {
		$latest->the_post();
		$date = get_post_modified_time( 'Y-m-d h:i:s', true );
		$last_mod = YoastSEO()->helpers->date->format( $date );
	}

	$url = "\t<url>\n";
	$url .= "\t\t<loc>$archive_url</loc>\n";
	$url .= "\t\t<lastmod>$last_mod</lastmod>\n";
	$url .= "\t</url>\n";

	return $url;

}
add_filter( 'wpseo_sitemap_page_content', 'add_archive_URL' );

Key things I changed:

  • Replaced get_the_modified_time with get_post_modified_time so that it would use GMT for the timezone, like the other dates in the XML file.
  • Changed the date format from Y-m-d h:i to Y-m-d h:i:s because we need to include seconds.
  • Filtered the date through YoastSEO()->helpers->date->format( $date ) which I copied from \wordpress-seo\inc\sitemaps\class-sitemaps-renderer.php - this puts the date in the same format used in the rest of the XML file.
  • I also added line breaks and tabs to the $url output, to match the layout of the rest of the XML file.

Hope that's helpful!

@acerus
Copy link

@acerus acerus commented Dec 22, 2020

@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

Thank you, those are actually very helpful adjustments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.