• Resolved one3rdnerd

    (@one3rdnerd)


    Hello,

    I am using WP Job Manager on a site and it forces the custom post type index to be /job-listings/ but we have used some custom PHP to make it render on /jobs/ and 301 redirect.

    The issue is that the sitemap for this post type still contains /job-listings/ at the top of the sitemap and ahrefs warns us about including a 301 in the sitemap.

    I have tried using variations of

    function sitemap_post_url( $url, $post ) {
        if ( $post->post_type === 'guest_authors' ) {
            return \str_replace( 'guest-authors', 'guests', $url );
        }
    
        return $url;
    }
    
    add_filter( 'wpseo_xml_sitemap_post_url', 'sitemap_post_url', 10, 2 );

    from https://developer.yoast.com/features/xml-sitemaps/api/#exclude-specific-posts but haven’t been able to make it change the index archive URL included in the sitemap.

    Any ideas?

    Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Maybellyne

    (@maybellyne)

    Hello One3rdnerd,

    Thanks for reaching out about your XML sitemap. If I understand correctly, you have used custom code to change the custom post type and create a 301 redirect from /job-listings/ to /jobs/. However, URLs of /job-listings/ still show in the sitemap.

    To exclude 301 redirects from a sitemap, these need to have been created with the Yoast SEO Premium plugin, as the Yoast-generated sitemap cannot exclude 301 redirects created with custom code or third-party plugins.

    Thread Starter one3rdnerd

    (@one3rdnerd)

    Hi @maybellyne

    That is correct, however, I don’t want to remove it I want to str_replace it with /jobs/, which the docs seem to suggest you can do with the code in my last comment but it doesn’t work.

    Is there another function? or is that function outdated and no longer working?

    Plugin Support devnihil

    (@devnihil)

    We’re sorry abut unfortunately we can’t offer support on custom code. Since we don’t want to take the risk that we break your website by suggesting incorrect or incomplete code, we cannot advise you on this or how to make changes to it. Maybe someone watching these forums can assist you further, but if your topic is inactive for 7 days, we’ll mark it as resolved to keep the overview.

    Thank you for your understanding.

    Thread Starter one3rdnerd

    (@one3rdnerd)

    @devnihil

    No problem. Switching Yoast SEO off and Rank Math on allowed us to solve this problem.

    Moving all of our sites off Yoast moving forward.

    Will leave this open in case someone can fix it for others.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘str_replace a custom post type index’ is closed to new replies.