Is it possible to use a number for a post/page slug? I have tried to use e.g. ‘123’ for my page slug, but each time WordPress converts it to ‘123-2’.
I’m guessing that any number is perhaps interpreted by WP as an ID. The number I want to use has nothing to do with post/page IDs. Can I get around this?
And yes, I have a good reason for using a number in stead of text in this case 🙂
Edit: On a related, more general note, what restrictions are there on what you can put in a slug? I have found that I also can’t use the + sign, though I’ve had that character in file names working just fine.
It’s only Pages where this is an issue. Posts are fine.
Seems like a bug to me, but regardless of whether or not it’s a bug, you can not use numeric slugs on pages.
This is because number slugs like “/750/” interfere with posts years “/2010/” etc. and WordPress can’t tell the difference.
If you save two pages to draft with the same number (say 750) then WordPress assigns the slug 750-2 to both. Upon publish, the first will stay 750-2 while the second will update to 750-3. There is no normal way to get slug 750 on a page as of 3.0
Update: http://core.trac.wordpress.org/ticket/11917 is the ticket that outlawed numeric slugs.
Short answer: Yes, it’s possible.
I had no problems to use a numbered slug, on concrete it was “56789”. The -2 get’s attached in case you have a slug already in use so it get’s prefixed with a additional number.
It does generally work because a slug is a string and those numbers are a string as well, there is no interpreter running identifying your slug suggestion as number and then handling it in some other way as identifying as english words.
So you could browse your blog with the slug 123 and take a look what’s there. Additionally you might take a peek in your database and look for the slug in the data itself, because it might get used in an attachment or so.
Update: I can have the slug
123
as well – just for the info. No problem with that number and this pretty permalink settings:/%year%/%monthnum%/%postname%
.this plugin worked for me https://github.com/Automattic/allow-numeric-stubs
worth searching the post_name in wp_posts just to check you don’t have duplicate post as well.
I’m pretty sure it’s not possible to use numbers for slugs due to the fact that the url rewriting process. I don’t know the exact technical reason for it but I can see why it would need to prevent numeric slugs from matching the actual numeric page ID.
It’s absolutely possible to use numbers for page slugs. However, adding a random number to the end of a page URL will always return that page (unless it matches another page’s URL), since the rewrite engine tacks on numbers to match the ends of page permastructs to allow for pagination inside of posts. My guess is you have some post somewhere in your database that is using 123 as its slug (could be an image or other attachment, or a menu item, or something else). If you fix that, you should be able to set your page’s slug to 123, and it will work. WordPress adds rewrite rules for each page individually, so it’s not a problem of it not recognizing it.