Documentation

Developer documentation for Default Permalink: hooks, options and customization.

How slug replacement works

The plugin hooks into the wp_unique_post_slug filter (priority 10, 4 arguments) and replaces the slug only when all of the following conditions are met:

  1. The df_enable option is "Enable" (enabled on the settings page).
  2. The post ID is not 0 (skipped for direct wp_insert_post calls without an ID, preventing colliding post-0 slugs).
  3. The post type is targeted (all public post types when the option has never been saved).
  4. The slug matches the regular expression /(%[0-9a-f]{2})+/ (contains URL-encoded multi-byte characters).
  5. The post’s post_name is empty (the user has not explicitly specified a slug).

On replacement, the new slug is stored in the _dp_slug_replaced post meta, which is used for the admin notice (deleted after the notice is shown).

Options

OptionValuesDescription
df_enable"Enable" / ""Whether the plugin’s behavior is enabled
df_slug_formatpost_type / date / randomSlug format (default: post_type)
df_post_typesArray of post type namesTargeted post types. All public post types when never saved (installs older than v1.4)

The default_permalink_slug filter

The generated slug is passed through the default_permalink_slug filter, so themes and other plugins can freely customize the format.

/**
 * Example: change the generated slug to "item-{post_ID}".
 *
 * @param string $slug      The generated slug.
 * @param int    $post_id   The post ID.
 * @param string $post_type The post type.
 */
add_filter( 'default_permalink_slug', function ( $slug, $post_id, $post_type ) {
	return 'item-' . $post_id;
}, 10, 3 );

Uninstall

Deleting the plugin runs uninstall.php, which removes all of the options above. Converted post slugs are part of the post data itself and remain unchanged.

Source code

Copied title and URL