12

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.

1
  • One interesting thing is that it occurs when using 4 characters length numeric slug only. Commented Apr 29, 2015 at 10:42

5 Answers 5

14

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.

2
  • Not a bug, it is the way it was designed: core.trac.wordpress.org/ticket/11863 Mind you I don't particularly agree with that decision but it is what it is (if you or others don't like this then by all means go and comment on that track ticket expressing your opinion, or create another ticket to discuss the issue and post the link here.) Commented Aug 19, 2010 at 18:10
  • Regardless, the answer to the question is "No, not for pages. Only post slugs can be numbers. Pages will get a suffix." Commented Jan 26, 2011 at 2:16
1

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.

0

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.

0

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.

0

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% .

3
  • did you perhaps get away with using such a high numeric value because it was a lot bigger than any possible page IDs for pages in your site? Commented Aug 18, 2010 at 11:50
  • Thanks for your answer. I did not define any page with the slug, so it's not a pre-existing slug issue. I did browse to the location (why didn't I think of that?), e.g. http://mysite/parent/child/123 and was shown the same content as for http://mysite/parent/child/ - it does not matter which number I put in there.
    – avesse
    Commented Aug 18, 2010 at 13:43
  • What's the highest number for page ID? Tada: bigint(20) UNSIGNED has a maximum of 18 446 744 073 709 551 615 (dev.mysql.com/doc/refman/5.0/en/numeric-types.html). But well, maybe there is an esoteric number mode in slugs?
    – hakre
    Commented Aug 18, 2010 at 15:23

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.