0

I have a CPT portfolio and a default permastructure /blog/%postname%/

When i add a blogpost www.domain.com/blog/blogname

When i add a page www.domain.com/pagename

But when i add a portfolio the permalink is:

www.domain.com/blog/portfolio/portfolioname

I want: www.domain.com/portfolio/portfolioname

How can i achieve that?

function cpt_portfolios() {

$labels = array(
    'name'                  => _x( 'Portfolio\'s', 'Post Type General Name', 'Portfolio' ),
    'singular_name'         => _x( 'Portfolio', 'Post Type Singular Name', 'Portfolio' ),
    'menu_name'             => __( 'Portfolio\'s', 'Portfolio' ),
    'name_admin_bar'        => __( 'Portfolio\'s', 'Portfolio' ),
    'archives'              => __( 'Item Archives', 'Portfolio' ),
    'parent_item_colon'     => __( 'Parent Item:', 'Portfolio' ),
    'all_items'             => __( 'All Items', 'Portfolio' ),
    'add_new_item'          => __( 'Add New Item', 'Portfolio' ),
    'add_new'               => __( 'Add New', 'Portfolio' ),
    'new_item'              => __( 'New Item', 'Portfolio' ),
    'edit_item'             => __( 'Edit Item', 'Portfolio' ),
    'update_item'           => __( 'Update Item', 'Portfolio' ),
    'view_item'             => __( 'View Item', 'Portfolio' ),
    'search_items'          => __( 'Search Item', 'Portfolio' ),
    'not_found'             => __( 'Not found', 'Portfolio' ),
    'not_found_in_trash'    => __( 'Not found in Trash', 'Portfolio' ),
    'featured_image'        => __( 'Featured Image', 'Portfolio' ),
    'set_featured_image'    => __( 'Set featured image', 'Portfolio' ),
    'remove_featured_image' => __( 'Remove featured image', 'Portfolio' ),
    'use_featured_image'    => __( 'Use as featured image', 'Portfolio' ),
    'insert_into_item'      => __( 'Insert into item', 'Portfolio' ),
    'uploaded_to_this_item' => __( 'Uploaded to this item', 'Portfolio' ),
    'items_list'            => __( 'Items list', 'Portfolio' ),
    'items_list_navigation' => __( 'Items list navigation', 'Portfolio' ),
    'filter_items_list'     => __( 'Filter items list', 'Portfolio' ),
);
$args = array(
    'label'                 => __( 'Portfolio', 'Portfolio' ),
    'description'           => __( 'Portfolio\'s CPT', 'Portfolio' ),
    'labels'                => $labels,
    'supports'              => array( 'title' ),
    'taxonomies'            => array(),
    'hierarchical'          => false,
    'public'                => true,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'menu_position'         => 5,
    'menu_icon'             => 'dashicons-welcome-add-page',
    'show_in_admin_bar'     => true,
    'show_in_nav_menus'     => true,
    'can_export'            => true,
    'has_archive'           => true,
    'exclude_from_search'   => false,
    'publicly_queryable'    => true,
    'capability_type'       => 'page',
);
register_post_type( 'portfolio', $args );

}
add_action( 'init', 'cpt_portfolios', 0 );
2
  • Please show the code you use to register your post type.
    – Milo
    Jan 12, 2018 at 16:18
  • @Milo see the edit Milo, hope you can help!
    – Bas
    Jan 15, 2018 at 7:12

1 Answer 1

0

Your $args array is missing the rewrite argument, specifically with_front, which is what controls whether or not the permalink front is added to the CPT.

$args = array(
    'rewrite' => array( 'slug' => 'portfolio', 'with_front' => false ),
    // other args...
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.