pre_wp_unique_post_slug filter-hookWP 5.1.0

Filters the post slug before it is generated to be unique.

Returning a non-null value will short-circuit the unique slug generation, returning the passed value instead.


add_filter( 'pre_wp_unique_post_slug', 'wp_kama_pre_wp_unique_post_slug_filter', 10, 6 );

 * Function for `pre_wp_unique_post_slug` filter-hook.
 * @param string|null $override_slug Short-circuit return value.
 * @param string      $slug          The desired slug (post_name).
 * @param int         $post_id       Post ID.
 * @param string      $post_status   The post status.
 * @param string      $post_type     Post type.
 * @param int         $post_parent   Post parent ID.
 * @return string|null
function wp_kama_pre_wp_unique_post_slug_filter( $override_slug, $slug, $post_id, $post_status, $post_type, $post_parent ){

	// filter...
	return $override_slug;
Short-circuit return value.
The desired slug (post_name).
Post ID.
The post status.
Post type.
Post parent ID.


Since 5.1.0 Introduced.

Where the hook is called

wp-includes/post.php 5118
$override_slug = apply_filters( 'pre_wp_unique_post_slug', null, $slug, $post_id, $post_status, $post_type, $post_parent );

Where the hook is used in WordPress

wp-includes/default-filters.php 718
add_filter( 'pre_wp_unique_post_slug', 'wp_filter_wp_template_unique_post_slug', 10, 5 );