Title: str_replace a custom post type index
Last modified: July 19, 2022

---

# str_replace a custom post type index

 *  Resolved [one3rdnerd](https://wordpress.org/support/users/one3rdnerd/)
 * (@one3rdnerd)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/str_replace-a-custom-post-type-index/)
 * 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](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](https://wordpress.org/support/users/maybellyne/)
 * (@maybellyne)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/str_replace-a-custom-post-type-index/#post-15866847)
 * 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](https://wordpress.org/support/users/one3rdnerd/)
 * (@one3rdnerd)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/str_replace-a-custom-post-type-index/#post-15867507)
 * Hi [@maybellyne](https://wordpress.org/support/users/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?
 *  [devnihil](https://wordpress.org/support/users/devnihil/)
 * (@devnihil)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/str_replace-a-custom-post-type-index/#post-15896613)
 * 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](https://wordpress.org/support/users/one3rdnerd/)
 * (@one3rdnerd)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/str_replace-a-custom-post-type-index/#post-15899106)
 * [@devnihil](https://wordpress.org/support/users/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.

 * ![](https://ps.w.org/wordpress-seo/assets/icon-256x256.gif?rev=3419908)
 * [Yoast SEO - Advanced SEO with real-time guidance and built-in AI](https://wordpress.org/plugins/wordpress-seo/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-seo/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-seo/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-seo/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-seo/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-seo/reviews/)

 * 4 replies
 * 3 participants
 * Last reply from: [one3rdnerd](https://wordpress.org/support/users/one3rdnerd/)
 * Last activity: [3 years, 10 months ago](https://wordpress.org/support/topic/str_replace-a-custom-post-type-index/#post-15899106)
 * Status: resolved