Title: Empty slug for rewrite?
Last modified: August 20, 2016

---

# Empty slug for rewrite?

 *  [ciantic](https://wordpress.org/support/users/ciantic/)
 * (@ciantic)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/empty-slug-for-rewrite/)
 * Hi!
 * Many have pondered this, [here](http://wordpress.org/support/topic/custom-post-type-rewrite-permalink-and-exclude-base),
   [here](http://wordpress.org/support/topic/how-can-i-create-a-custom-post-type-with-empty-slug)
   and [here](http://wordpress.org/support/topic/custom-post-type-rewrite-permalink-and-exclude-base).
 * So the scoop is that with this:
 *  `register_post_type( 'test', array(..., 'rewrite' => array('slug' => '', 'with_front'
   => true)));`
 * (Some instructions have _with\_front_ as `false` but it doesn’t work that way
   either)
 * One could get post URLs without the ugly ‘test’ in front. But it does not work
   in **3.2.1** for me at least. Anyone got it working?
 * Empty slug ” it only redirects to the `/test/post-name/`. With `'/'` as slug 
   I get 404. With `'a'` as slug it works just fine it redirects to `'/a/post-name/'`
   but I don’t want any prefix.
 * To refresh the permalinks I always go to `/wp-admin/options-permalink.php` and
   save, it seems to refresh them if I put single char to the slug for instance.
 * P.S. I also have flush_rewrite_rules() in activation hook.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [ciantic](https://wordpress.org/support/users/ciantic/)
 * (@ciantic)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/empty-slug-for-rewrite/#post-2282893)
 * Evidently this empty slug cannot work, if one looks at the source code [Line 991 in _wp-includes/post.php_ (3.2.1)](http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/post.php#L991):
 * `991 if ( empty( $args->rewrite['slug'] ) )
    992 $args->rewrite['slug'] = $post_type;
 * Now same part of code in 3.0 was like this:
 * [http://core.trac.wordpress.org/browser/tags/3.0/wp-includes/post.php#L865](http://core.trac.wordpress.org/browser/tags/3.0/wp-includes/post.php#L865)
 * `865 if ( !isset($args->rewrite['slug']) )
    866 $args->rewrite['slug'] = $post_type;
 * Why was it changed to empty? Now one cannot use ” anymore. Argh!
 *  Thread Starter [ciantic](https://wordpress.org/support/users/ciantic/)
 * (@ciantic)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/empty-slug-for-rewrite/#post-2282897)
 * I tried to circumvent this by doing like this:
 * `
    class NonEmptyString { public function __toString() { return ''; } }
 * ...
 * 'slug' => new NonEmptyString()
 * It gives 404 and seems to fail just like the `'/'`. Hmm, what is this 404 I keep
   getting then.
 *  Thread Starter [ciantic](https://wordpress.org/support/users/ciantic/)
 * (@ciantic)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/empty-slug-for-rewrite/#post-2282901)
 * If I set hierarchical to **false** and slug to `/` it kinda works, but it page
   links doesn’t work anymore.
 * Must test more.
 *  Thread Starter [ciantic](https://wordpress.org/support/users/ciantic/)
 * (@ciantic)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/empty-slug-for-rewrite/#post-2282902)
 * Ah found the official answer: Don’t do it, instead if you must set rewrite = 
   false and write your own rewrite.
 * [http://core.trac.wordpress.org/ticket/15082](http://core.trac.wordpress.org/ticket/15082)
 * Now I must discover how to do this custom rewrite.
 *  [shirazdrum](https://wordpress.org/support/users/shirazdrum/)
 * (@shirazdrum)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/empty-slug-for-rewrite/#post-2282931)
 * Just the delete the slug from your database using phpmyadmin.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Empty slug for rewrite?’ is closed to new replies.

## Tags

 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [permalinks](https://wordpress.org/support/topic-tag/permalinks/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [shirazdrum](https://wordpress.org/support/users/shirazdrum/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/empty-slug-for-rewrite/#post-2282931)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
