Why can't I save permalink “360” for a page?
I am trying to save my page with permalink "360" but for some reason WP keeps updating the permalink to "360-2". I have checked everywhere in my WP and there is no page or post that uses permalink "360". Is 360 a permalink for something internal? If not, what is the problem?
Answers 3
The problem comes with using only numbers as URLs. Here is a forum thread in WP that discuss this issue. I'll cite Otto:
If we check out the source of the
wp_unique_post_slug()
function, then we see that this is expected for hierarchical post types, other thannav_menu_item
.If we try for example the slugs
360
orpage360
, then the-n
slug suffix will show up.We can play with e.g.:
or
to see that.
One of the "bad slug" checks, within
wp_unique_post_slug()
, is this one:It's matched in your case:
hence the resulting slug suffix.
You can also play with it here:
https://regex101.com/r/jF3kC6/1
Note that it's possible to modify the slug via the
wp_unique_post_slug
filter, but one should be really careful doing that.Here's what I did if you don't like plugins for a simple job:
"@^\d+-2$@"
matches numeric slug with-2
postfix.I actually just check for
-2
if it has been added cause in the other case it means that you already have e.g.360-2
page which seems weird to me, but I suppose you got the idea.