1. Home
  2. Docs
  3. Filters & Hooks
  4. How to use post IDs instead of slugs (post names)?

How to use post IDs instead of slugs (post names)?

First of all you will need to stop the slugs from being added to the default custom permalinks following this short instructions.

You can find more detailed description here.

Once it is done, you should adjust the permastructures settings and use %post_id% tag inside the permastructure input fields (“Tools -> Permalink Manager -> Permastructures“):

Please also note that that numerals in the end of permalinks will be parsed as pagination endpoints and therefore the custom URIs will not be detected correctly. To fix this issue please enable “Deep detect” mode with one more snippet:

add_filter('permalink-manager-deep-uri-detect', '__return_true', 99);

Apply the new permalink rules to the old URIs:

The new rules will not be applied automatically, to apply them to the old posts please follow this short tutorial.

Full sample code

The code listed above if used would prevent the page and product slugs from being added to the end of permalink and also enable “Deep detect” mode, so the permalinks ended with numerals can be parsed properly.

function pm_donot_append_product_slug($bool, $post_type) {
	return (in_array($post_type, array('product', 'page'))) ? true : $bool;
}
add_filter('permalink_manager_do_not_append_slug', 'pm_donot_append_product_slug', 9, 2);
add_filter('permalink-manager-deep-uri-detect', '__return_true', 99);
Was this article helpful to you? Yes No

How can we help?

Wait!!! Before you go...

Still not convinced? Use following discount code during Gumroad checkout and get 10% off!

BLOG

If you have any questions or need further information, please feel free to contact me via email: