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:
- The
df_enableoption is"Enable"(enabled on the settings page). - The post ID is not 0 (skipped for direct
wp_insert_postcalls without an ID, preventing collidingpost-0slugs). - The post type is targeted (all public post types when the option has never been saved).
- The slug matches the regular expression
/(%[0-9a-f]{2})+/(contains URL-encoded multi-byte characters). - The post’s
post_nameis 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
| Option | Values | Description |
|---|---|---|
df_enable | "Enable" / "" | Whether the plugin’s behavior is enabled |
df_slug_format | post_type / date / random | Slug format (default: post_type) |
df_post_types | Array of post type names | Targeted 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.