Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to turn /{custom-post-type}/{post-name} to /{post-name}, is this possible?

If this is not possible, can I change the labels/terminology in Pages or Posts so that they could be called "Clients" or "Projects" etc?

share|improve this question

3 Answers 3

'rewrite' => array('slug' => '/', 'with_front' => false)

This will get the url correctly formed for you, but it will 404 unless you handle it in your theme.

share|improve this answer

From the codex

When you namespace a URL and still want to use a "clean" URL structure, you need to add the "rewrite" element to the array. For example, assuming the "ACME Widgets" example from above:

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

The above will result in a URL like http:/example.com/products/%product_name% (see description of %product_name% above.) Note that we used a plural form here which is a format that some people prefer because it implies a more logical URL for a page that embeds a list of products, i.e. http:/example.com/products/.

Also note using a generic name like "products" here can potentially conflict with other plugins or themes that use the same name but most people would dislike longer and more obscure URLs like http:/example.com/acme_products/foobrozinator and resolving the URL conflict between two plugins is easier simply because the URL structure is not stored persistently in each post record in the database in the same way custom post type names are stored.

share|improve this answer
    
I think you misunderstand, I want the posts to have clean URLs but I do not want to have a post-type slug (the method you have quoted from the codex). –  Tom Jan 11 '12 at 11:20

I just changed a slug for a custom post type (in this case, I changed it from "best-practices" to "bestpractices"). I had copied some code that had a blank slug, like so:

'rewrite' => array('slug' => ''),

Since it was originally left blank, Wordpress was just using the name of the custom post type ("best-practices") as the slug. I changed my line of code to

'rewrite' => array('slug' => 'bestpractices'),

I just wanted to note here that you'll need to reset your permalinks to get the change to take effect, if you're changing slugs on pre-existing custom post types.

share|improve this answer
    
THANK YOU! I just spent an hour trying to figure out why my permalinks weren't updating. I didn't realize you'd need to go into the admin and "Save" your permalink structure again. –  Nathan J. Brauer Aug 27 at 6:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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