Filter hook 'pre_wp_unique_post_slug'

in WP Core File wp-includes/post.php at line 5400

View Source

pre_wp_unique_post_slug

Filter Hook
Description
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.

Hook Information

File Location wp-includes/post.php View on GitHub
Hook Type Filter
Line Number 5400

Hook Parameters

Type Name Description
string|null $override_slug Short-circuit return value.
string $slug The desired slug (post_name).
int $post_id Post ID.
string $post_status The post status.
string $post_type Post type.
int $post_parent Post parent ID.

Usage Examples

Basic Usage
<?php
// Hook into pre_wp_unique_post_slug
add_filter('pre_wp_unique_post_slug', 'my_custom_filter', 10, 6);

function my_custom_filter($override_slug, $slug, $post_id, $post_status, $post_type, $post_parent) {
    // Your custom filtering logic here
    return $override_slug;
}

Source Code Context

wp-includes/post.php:5400 - How this hook is used in WordPress core
<?php
5395  	 * @param int         $post_id       Post ID.
5396  	 * @param string      $post_status   The post status.
5397  	 * @param string      $post_type     Post type.
5398  	 * @param int         $post_parent   Post parent ID.
5399  	 */
5400  	$override_slug = apply_filters( 'pre_wp_unique_post_slug', null, $slug, $post_id, $post_status, $post_type, $post_parent );
5401  	if ( null !== $override_slug ) {
5402  		return $override_slug;
5403  	}
5404  
5405  	global $wpdb, $wp_rewrite;

PHP Documentation

<?php
/**
	 * 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.
	 *
	 * @since 5.1.0
	 *
	 * @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.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 6
  • File: wp-includes/post.php
Related Hooks

Related hooks will be displayed here in future updates.