0

I have a post type named careers which is,

function do_careers() {
 register_post_type('Careers', array(
    'labels' => array(
        'name' => 'Careers',
        'singular_name' => 'Career',
        'add_new_item' => 'Add New Career',
        'edit_item' => 'Edit Career',
    ),
    'description' => 'Careers',
    'public' => true,
    'menu_position' => 20,
    'supports' => array('title')
 ));
}

add_action('init', 'do_careers');

And for the purpose of having /blog/ in permalink of posts I have the custom permalink structure like,

/blog/%postname%/

When I have /blog/ part in the custom permalink I see the career permalink like this https://www.abcd.net/blog/careers/blah-blah-blah/.

When I only have the /%postname%/ in custom permalink I can see that my blog post permalink shows like https://www.abcd.net/blah-blah-blah/. Part/blog/ is not here, but career link is perfect like https://www.abcd.net/careers/blah-blah-blah/.

I want then permalink in the following pattern for all posts(including custom post types).

https://www.abcd.net/post_type/post_name

3

The rewrite argument of register_post_type() will help you with this. The rewrite argument is an array of different arguments, the one you'll need is with_front, which desides whether the permalink base is prepended to your post type. It defaults to true, setting it to false will not include the permalink structure in the permalink. It would look something like this:

function do_careers() {
 register_post_type('Careers', array(
    'labels' => array(
        'name' => 'Careers',
        'singular_name' => 'Career',
        'add_new_item' => 'Add New Career',
        'edit_item' => 'Edit Career',
    ),
    'description' => 'Careers',
    'public' => true,
    'menu_position' => 20,
    'supports' => array('title'),
    'rewrite' => array(
        'with_front' => false,
    ),
 ));
}

add_action('init', 'do_careers');

You can also add a slug argument to the rewrite array to make the post type slug different from the post type name, if you wish to do so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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