GithubHelp home page GithubHelp logo

Comments (9)

sybrew avatar sybrew commented on May 31, 2024

Hi @ovizii,

Thanks for this! I now noticed I made a typo in the CPT sitemap generation :(.

Anyway, in order to remove replies from the sitemap, please use the following snippet, using this filter:

add_filter( 'the_seo_framework_sitemap_exclude_cpt', 'my_sitemap_exlusions' );
function my_sitemap_exclusions( $exclusions = array() ) {

    $exclusions[] = 'replies';
    //* You can add more exclusions, for example:
    $exclusions[] = 'forums';

    return $exclusions;
}

You can reset the sitemap's cache by updating a post/page, or by re-saving the SEO Settings.

I hope this helps! Cheers 😄

from the-seo-framework.

ovizii avatar ovizii commented on May 31, 2024

thanks for the quick reply and the snippet.

hm, that didn't seem to work. Are you sure I need to exclude "replies" and not "reply"?
I've edited a page and re-saved the settings and invalidated

from the-seo-framework.

sybrew avatar sybrew commented on May 31, 2024

Hi ovizii,

I'm not sure if it's reply or replies.

The only way you can be certain is to dump the current post type on the said page, or dump all public post types and make your picks from there: get_post_types( array( 'public' => true ) );

But before that, I'd suggest trying reply :).

from the-seo-framework.

ovizii avatar ovizii commented on May 31, 2024

hm, I dumped all of them:
<?php foreach ( get_post_types( '', 'names' ) as $post_type ) { echo '<p>' . $post_type . '</p>'; } ?>
Result:

post, page, attachment, revision, nav_menu_item, forum, topic, reply, bp-email, postman_sent_mail

so I then inserted reply into your previous snippet and yet no change. Any more ideas? Does your snippet work for you? Here is what is inside my functions.php

/* Added to remove replies from the sitemap */

add_filter( 'the_seo_framework_sitemap_exclude_cpt', 'my_sitemap_exlusions' );
function my_sitemap_exclusions( $exclusions = array() ) {

$exclusions[] = 'reply';
return $exclusions;

}

from the-seo-framework.

sybrew avatar sybrew commented on May 31, 2024

Hi @ovizii,

I still have a very hard time using bbPress on my test server... no settings for the forums are shown 😕.
Nevertheless, I figured it out 😄.

It's not working because I made a typo:

my_sitemap_exlusions
my_sitemap_exclusions

You'd have to change the function name or the callback name accordingly so they're equal.

In your case, this snippet should work as expected, don't forget to flush the sitemap's cache by re-saving the SEO settings:

add_filter( 'the_seo_framework_sitemap_exclude_cpt', 'my_sitemap_exclusions' );
function my_sitemap_exclusions( $exclusions = array() ) {

    $exclusions[] = 'reply';

    return $exclusions;
}

Cheers!

P.S. You'll need to use three backticks with a line-feed/return to write code blocks at GitHub.
P.P.S. Unfortunately, I do not have the time to test all code snippets I post here or on the WordPress.org forums. I used to do that, but I noticed it eats out hours of my day; so I write quick examples based on estimations. I hope you understand, and I'm sorry to have wasted some of your time by doing so :(.

from the-seo-framework.

ovizii avatar ovizii commented on May 31, 2024

Hi and thanks for the help so far. Absolutely no need to explain yourself, this is outstanding support you're doing here for free. Thanks for the tip with the "```" :-)

I should have looked closer at the snippet you provided, I could have caught that typo myself.

I can confirm this all works as expected! Thanks a lot, maybe add this to the plugin FAQ as a link?

from the-seo-framework.

sybrew avatar sybrew commented on May 31, 2024

Anytime! I'm glad it worked out.

A knowledge base/FAQ is certainly planned, and I have more than enough data to fill it in 😄.
Even more so, an automated plugin function documentation system is planned, as seen on https://developers.wordpress.org/. But that's a project for later.

For now, filters, constants and other things are shown at The SEO Framework API docs. It requires some updates (rather a complete rework 😝), but most information is already present.

Have a wonderful day!

from the-seo-framework.

cjyabraham avatar cjyabraham commented on May 31, 2024

My sense is that this method no longer works? I can't find the the_seo_framework_sitemap_exclude_cpt hook in the plugin code. How do I remove a CPT from being listed in the sitemap?

from the-seo-framework.

sybrew avatar sybrew commented on May 31, 2024

Hi @cjyabraham

For best performance, I recommend using the_seo_framework_sitemap_supported_post_types now. It's a sequential array of supported post types.

add_filter( 'the_seo_framework_sitemap_supported_post_types', function( $post_types ) {
	return array_diff( $post_types, [ 'exclude_this_post_type', 'exclude_me_too' ] );
} );

Cheers!

from the-seo-framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.