Henry
Henry

Reputation: 5311

'Bug' in WordPress? All URL's are appended with a '-2'

This is odd...

When I create a page (either draft or published) WordPress does its' job by creating/ suggestion a URL File Name.

For some reason it always appends a '-2' (without apostrophes)

So, for example - /exampleABC/ become automatically /exampleABC-2/

At first I thought it was because there was a draft version of the file or one in existence, but that isn't the case.

I've no idea how best to error-check here - any ideas what I should be looking for? Thanks

Upvotes: 1

Views: 134

Answers (1)

random_user_name
random_user_name

Reputation: 26170

The current version of WordPress (version 4.5.1) does not have this "bug". Therefore, one of a few possibilities is happening for you:

Possibility 1: You have slug conflicts.

This is the way that WordPress resolves "slug" conflicts. So - the thing that you have to remember is that ANY record in the posts table - whether for a page, post, custom post type, etc - and even media - will have a slug. As @McNab points out - this includes the posts (and media) in the trash. If the slug for the page you are creating conflicts with any existing slug, then WP will automatically append a number (and "increment" it as appropriate):

Saving example - if a post with the slug example exists, will result in a new slug of example-2. If example-2 already exists, then example-3, etc.

Possibility 2: You have a plugin that is causing this issue.

Always keep in mind that plugins can do a LOT, given the power and flexibility of WP, and it's conceivable that a plugin (or your theme) could be causing this.

Possibility 3: Your site is hacked.

Similar to #2, there may be a nefarious / malicious plugin, theme, or "hack" on your site, which is causing this.

However - my strong guess is that it's just possibility 1 - you have other records in the posts table with the slug already existing.

How to know / prove it?

If I were testing / debugging this, I would take the following steps:

  1. Create a page with a crazy, unique page title: "xyzpdqaaa" or similar. Save it. What is the slug? If it's "xyzpdqaaa-2" (aka "wrong"), then possibility one is (probably) ruled out. If it's "xyzpdqaa" (aka "right"), then everything is fine, and you just have slug conflicts.
  2. If the slug turns out to be "xyzpdqaaa-2", then I would disable ALL plugins. (This is a pain, and I hate doing it, but it truly is the way to prove it). Repeat step 1 (with a new "crazy unique" title) - if it's correct, then you've got a plugin causing the problem.
  3. If it is a plugin, start enabling plugins. Typically I work in "halves" - enable HALF the plugins (do your best guess at which one(s) are safe - and enable those first). Test again. If OK, enable more (half of the remaining plugins), test again. If not ok, disable half the enabled ones. (Keep track of which you did / did not enable, so you can narrow down which plugin is causing the issue). Repeat until you narrow down the specific plugin causing problems.
  4. If it's not a plugin (it's still "wrong" even with all plugins disabled), then leave your plugins disabled, and switch themes. Test again. If it's still "wrong", then your site is hacked - clean up the hack. If it's "right", then your theme is the culprit.

Upvotes: 2

Related Questions