Change the custom post type permalink

You can use rewrite arg in register_post_type. You can have custom post type name different then rewrite slug. For example here is the sample code with custom post type project and it shows pages with http://shaowtriger.com/brands/naim/

Notice rewrite in $args

add_action( 'init', 'codex_brand_init' );
function codex_brand_init() {
  $labels = array(
    'name'               => _x( 'Brands', 'post type general name', 'your-plugin-textdomain' ),
    'singular_name'      => _x( 'Brand', 'post type singular name', 'your-plugin-textdomain' ),
    'menu_name'          => _x( 'Brands', 'admin menu', 'your-plugin-textdomain' ),
    'name_admin_bar'     => _x( 'Brand', 'add new on admin bar', 'your-plugin-textdomain' ),
    'add_new'            => _x( 'Add New', 'brand', 'your-plugin-textdomain' ),
    'add_new_item'       => __( 'Add New Brand', 'your-plugin-textdomain' ),
    'new_item'           => __( 'New Brand', 'your-plugin-textdomain' ),
    'edit_item'          => __( 'Edit Brand', 'your-plugin-textdomain' ),
    'view_item'          => __( 'View Brand', 'your-plugin-textdomain' ),
    'all_items'          => __( 'All Brands', 'your-plugin-textdomain' ),
    'search_items'       => __( 'Search Brands', 'your-plugin-textdomain' ),
    'parent_item_colon'  => __( 'Parent Brands:', 'your-plugin-textdomain' ),
    'not_found'          => __( 'No brands found.', 'your-plugin-textdomain' ),
    'not_found_in_trash' => __( 'No brands found in Trash.', 'your-plugin-textdomain' )
  );

  $args = array(
    'labels'             => $labels,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'brands' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
  );

  register_post_type( 'project', $args );
  flush_rewrite_rules();

}

Although having only base page http://shaowtriger.com/brands/ should not interfere with CPT slug and functionality but having subpages to page brands will not work because then WordPress will look for CPT item instead of subpage.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)