Change custom post type url

I’ve a custom post type by name ‘Portfolio’. It’s generating the url as /portfolio/xxx when I make any post. I want to change it to ‘Products’.
Change custom post-type rewrite
I’ve tried this but it doesn’t suppose to work.

Related posts

Leave a Reply

3 comments

  1. I am presuming you have added the custom post type yourself, in which case it is easy.

    When you register a new post type, you can set any rewrite rules for that post type to follow as part of the arguments used in the register_post_type( 'name', $args ) function.

    If your post type is available on the front end and is public, then by default WordPress will use the custom post name as the slug. You can override this as follows:

    $args = array(
        // your other arguments
        'rewrite' => array( 
            'slug' => 'products', // use this slug instead of post type name
            'with_front' => FALSE // if you have a permalink base such as /blog/ then setting this to false ensures your custom post type permalink structure will be /products/ instead of /blog/products/
        ),
    );
    
    register_post_type( 'portfolio', $args );
    

    The other arguments you can use are documented at http://codex.wordpress.org/Function_Reference/register_post_type

  2. Please see the documentation on URLs of Namespaced Custom Post Types Identifiers. One of the options available to you is to add a 'rewrite' argument to register_post_type(). From the docs:

    When you namespace a custom post type identifier and still want to use a clean URL structure, you need to set the rewrite argument of the register_post_type() function. For example:

    add_action( 'init', 'create_posttype' );
    function create_posttype() {
      register_post_type( 'acme_product',
        array(
          'labels' => array(
            'name' => __( 'Portfolio' ),
            'singular_name' => __( 'Portfolio' )
          ),
          'public' => true,
          'has_archive' => true,
          'rewrite' => array('slug' => 'products'),
        )
      );
    }
    

    You’ll then likely need to login to the admin and re-save your permalinks.

  3. Use the rewrite property

    $args= array(
        // other settings
        'rewrite' => array( 'slug' => 'Products' ),
    );
    register_post_type( 'portfolio', $args);