1

As you probably know, if a new post has the same post_name as another one, WordPress automatically appends it with -2, -3 etc.

But is there any way to add -1 at the end of a post if there isn't one with the same name?

I've tried altering various sections of posts.php but it I'm not sure what the relevant section is (or if that's even the right file to be looking at).

What I'm actually trying to do is add the $post_id to the start of all post_names which are written to the database (mainly so I can remove the suffix at the end). So far I've got it working on ones where the post_name is a duplicate, but I need it for new posts, too.

So instead of

www.mysite/another-post
www.mysite/another-post-2
www.mysite/a-different-post

it will show

www.mysite/118-another-post
www.mysite/119-another-post
www.mysite/120-a-different-post
www.mysite/121-you-get-the-point

Anyone know how to do this?

1

1 Answer 1

0

In Wordpress dashboard, go to Settings > Permalinks.

Click the 'Custom structure' option then put the following code in the box /%post_id%-%postname%/

2
  • No, that doesn't change the post_name that's written to the database, which is what I need it to do. But thanks anyway. Commented Jul 14, 2015 at 16:11
  • Sorry, I missed that part (but it does deliver those URLs!). Maybe something like this question would help? I don't edit the admin area myself.
    – Dub Scrib
    Commented Jul 14, 2015 at 16:39

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.