最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to rewrite slug of custom post type archive page

programmeradmin1浏览0评论

I have a CPT called "case-studies" and the slug of the archive page of this CPT is www.my-domain/case-studies and the slug of the CPT posts is www.my-domain/case-studies/case-study-name.

Now, for SEO purposes, I have to change the slug of the archive page to "testimonials-case-studies" so the slug for the "case-studies" archive page it has to be www.my-domain/testimonials-case-studies/ and the slug for the posts have to be www.my-domain/case-studies/case-study-name (same as before).

What is the best way or the solution for this?

What I have tried so far is:

  • creating a custom page template and change the slug of the page to /testimonials-case-studies/ and redirect /case-studies/ to /testimonials-case-studies/ but the posts www.my-domain/case-studies/case-study-name are not working because there is a problem with redirection.

  • Using:

    'rewrite' => array(
        'slug' => 'testimonials-case-studies',
        'with_front' => false
    ),
    

In the custom post type BUT the slug for the post change to www.my-domain/testimonials-case-studies/case-study-name but IT HAS to be: www.my-domain/case-studies/case-study-name

Is there a possible solution for this?

I have a CPT called "case-studies" and the slug of the archive page of this CPT is www.my-domain/case-studies and the slug of the CPT posts is www.my-domain/case-studies/case-study-name.

Now, for SEO purposes, I have to change the slug of the archive page to "testimonials-case-studies" so the slug for the "case-studies" archive page it has to be www.my-domain/testimonials-case-studies/ and the slug for the posts have to be www.my-domain/case-studies/case-study-name (same as before).

What is the best way or the solution for this?

What I have tried so far is:

  • creating a custom page template and change the slug of the page to /testimonials-case-studies/ and redirect /case-studies/ to /testimonials-case-studies/ but the posts www.my-domain/case-studies/case-study-name are not working because there is a problem with redirection.

  • Using:

    'rewrite' => array(
        'slug' => 'testimonials-case-studies',
        'with_front' => false
    ),
    

In the custom post type BUT the slug for the post change to www.my-domain/testimonials-case-studies/case-study-name but IT HAS to be: www.my-domain/case-studies/case-study-name

Is there a possible solution for this?

Share Improve this question edited Sep 29, 2019 at 21:26 wittich 1732 silver badges10 bronze badges asked Jul 5, 2018 at 16:03 andresglandresgl 1641 gold badge3 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 17

Pass the desired archive slug via has_archive:

$args = array(
    'rewrite'     => array( 'slug' => 'case-studies' ),
    'has_archive' => 'testimonials-case-studies',
);
发布评论

评论列表(0)

  1. 暂无评论