1. Home
  2. Docs
  3. Filters & Hooks
  4. How to programmatically change the custom permalinks?

How to programmatically change the custom permalinks?

One of the biggest advantages of Permalink Manager is a possibility to to dynamically manipulate the custom permalinks (parsed as $permalink_manager_uris global) assigned to any WordPress post, page or term using permalink-manager-uris filter.

Please remember that the custom URIs used by categories, tags or custom terms are stored in $permalink_manager_uris array with “tax-” prefix, eg.:

Array (
	[10] => custom-uri/used-by-a-single-post
	[12] => another-custom-uri/used-by-another-single-post
	...
	[tax-20] => custom-uri/used-by-a-single-term-tag-or-category
	[tax-28] => another-custom-term-permalink-example
)

Below you can find a sample filter that allows to modify the custom URIs array:

function pm_filter_custom_uris($custom_uris) {
	$custom_uris = (!is_array($custom_uris)) ? array() : $custom_uris;

	// Filter the permalink assigned to post/page/custom post item with id #99
	$custom_uris["99"] = "dynamically/changed/custom-uri";

	// Filter the permalink assigned to category/tag/custom term item with id #10
	// All terms should be prefixed with "tax-"
	$custom_uris["tax-10"] = "filtered-custom-uri/assigned-to-a-single-term";

	return $custom_uris;
}
add_filter('permalink-manager-uris', 'pm_filter_custom_uris', 9);
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: