skip to Main Content

In my wordpress website :

I need to modify permalink for the custom post type Rivista Quadrimestrale.

Now the permalink is :

https://www.sicilianmarketing.it/diritticomparati/rivista-trimestrale/%postname%

I need it to be

https://www.sicilianmarketing.it/diritticomparati/%postname%

Please help in this case.

2

Answers


  1. You can do it in apache or nginx if needed. You need to give the information to the browser by giving a 301 status code and the new link if called on the old.

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301

    Login or Signup to reply.
  2. In your functions.php try adding

    function cpt_remove_slug( $post_link, $post, $leavename ) {
        if ( 'rivista-trimestrale' != $post->post_type || 'publish' != $post->post_status ) {        return $post_link;    }
        $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
        return $post_link;
    }
    add_filter( 'post_type_link', 'cpt_remove_slug', 10, 3 );
    
    
    
    // Removes  the slug 
    
    function cpt_parse_request( $query ) {
        if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {        return;    }
        if ( ! empty( $query->query['name'] ) ) {        $query->set( 'post_type', array( 'post', 'rivista-trimestrale', 'page' ) );    }
    }
    add_action( 'pre_get_posts', 'cpt_parse_request' );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search