R
R
RigidStyle2018-04-26 15:06:04
WordPress
RigidStyle, 2018-04-26 15:06:04

How to set fixed length post_id (slug) in URL?

Good afternoon.
Currently in WordPress the link structure is /%category%/%post_id%/ , and by default the length of post_id is 3 digits. How to make post_id always be 5 random digits? That is, the URL of the article should always look like www.site.com/category/12345. That is, to limit the minimum length of the slug. How to limit the maximum length found a lot of information. But the minimum is not mentioned anywhere.
UPD:
Hypothesis.
Perhaps you need to do it through wp_unique_post_slug () here about it , which in turn issues the post slug through variables, here is the code as far as I understand.
Accordingly, you need to reassign this function through function.php, adding a new variable to it, for example post_random_slug, which is randomly generated there (for example, based on the already existing wp_generate_password() function, the one that generates passwords in WP, after adding a filter to it by characters, so that only numbers are), and then check whether there is such a slug, and if so, then re-generate, and if not, then return to wp_unique_post_slug(), and enter the site structure in the "permalinks" themselves .ru/%category%/%post_random_slug%/ after this variable is added.
But, unfortunately, mine is not a programmer. I can't write this four-line...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-04-26
@Sanasol

They won't be random because it's a post number.
As an idiocy, you can change autoincrement to 9999 in the database, and all the following will already be 5 digits.
Pointless and ruthless.
Well, or in routes, always use the slug typed by hand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question