0

I would like to know the correct way to setup the permalink structure for a custom post type.

Is there any attribute I am to set when I run a register_post_type() ?

e.g.

custom post type: product
expected permalink structure: /product/<slug>

1 Answer 1

1

I think you need to use the rewrite argument.

Here's an example setting the url to tips

$args = array(
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
    'rewrite' => array( 'slug' => 'tips' ), // Here!
    'capability_type' => 'post',
    'has_archive' => true, 
    'hierarchical' => false,
    'menu_position' => 20,
    'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'revisions', 'custom-fields')
  ); 

  register_post_type( 'tips', $args );

More info: http://codex.wordpress.org/Function_Reference/register_post_type

5
  • Ah I see. So this will make the permalink structure "/tips/<slug>" ? Jan 24, 2014 at 11:30
  • Yes, this will create: youdomain.com/tips/my-tip
    – Ricard
    Jan 24, 2014 at 11:33
  • And also, if I have the single-tips.php that would be the template for this post_type right ? Jan 24, 2014 at 11:37
  • 1
    You can have archive-tips.php and single-tips.php Check out: codex.wordpress.org/Post_Type_Templates
    – Ricard
    Jan 24, 2014 at 11:38
  • Wonderful ! Thanks. What an amazing software wordpress is ! Jan 24, 2014 at 11:47

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.