pre_wp_unique_post_slug
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.
Usage
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; }
- $override_slug(string|null)
- Short-circuit return value.
- $slug(string)
- The desired slug (post_name).
- $post_id(int)
- Post ID.
- $post_status(string)
- The post status.
- $post_type(string)
- Post type.
- $post_parent(int)
- Post parent ID.
Changelog
Since 5.1.0 | Introduced. |
Where the hook is called
pre_wp_unique_post_slug
wp-includes/post.php 5350
$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 721
add_filter( 'pre_wp_unique_post_slug', 'wp_filter_wp_template_unique_post_slug', 10, 5 );