Provides a slugField helper that adds a required, unique, indexed slug text field generated from a top-level or nested source field path. It supports optional persisted Auto/Manual mode per locale, custom sync or async slugifiers, and a live preview in the admin. An optional slug() plugin registers English labels and enables custom preview. Requires Payload 3.94.1 or newer below 4, and is ESM only.
A Payload CMS field that generates URL-friendly slugs from top-level or nested source paths and enforces uniqueness, with optional persisted Auto/Manual control.
Installation
npm i @klnap/payload-slug0
Stars
0
Forks
0
Open Issues
Yesterday
Last Updated
2.5k
Weekly Downloads
v0.3.2
npm Version
193.1 KB
Unpacked Size
1
Dependencies
00 since Nov 22
| Date | Stars |
|---|---|
| Dec 5, 2026 | 0 |
| Dec 4, 2026 | 0 |
| Dec 3, 2026 | 0 |
| Dec 2, 2026 | 0 |
| Dec 1, 2026 | 0 |
| Nov 30, 2026 | 0 |
| Nov 29, 2026 | 0 |
| Nov 28, 2026 | 0 |
| Nov 27, 2026 | 0 |
| Nov 26, 2026 | 0 |
| Nov 25, 2026 | 0 |
| Nov 24, 2026 | 0 |
| Nov 23, 2026 | 0 |
| Nov 22, 2026 | 0 |
2.4K+2.4K since Nov 27
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 2,399 |
| Dec 4, 2026 | 2,496 |
| Dec 3, 2026 | 2,376 |
| Dec 2, 2026 | 2,323 |
| Dec 1, 2026 | 2,199 |
| Nov 30, 2026 | 861 |
| Nov 29, 2026 | 583 |
| Nov 28, 2026 | 412 |
| Nov 27, 2026 | 17 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1469459976-root)<a href="https://payloaddirectory.dev/plugins/1469459976-root"><img src="https://payloaddirectory.dev/badge/1469459976-root.svg" alt="Payload Directory"></a>README
Slug fields for Payload CMS with live preview, automatic and manual modes, localization, and nested source paths.
Per-locale persisted modes, live preview, custom slugification, and stable Auto slugs.
bun add @klnap/payload-slug
# or
npm install @klnap/payload-slug
import type { CollectionConfig } from "payload";
import { slugField } from "@klnap/payload-slug";
export const Posts: CollectionConfig = {
slug: "posts",
fields: [
{ name: "title", type: "text", required: true },
slugField({ source: "title", modeToggle: true }),
],
};
Use slugField() for the field, Admin component, built-in preview, and save hook. Register slug() for English labels or custom preview; server callbacks work without it.
import type { Plugin } from "payload";
import { slug } from "@klnap/payload-slug";
const plugins: Plugin[] = [slug()];
Payload's native slug field also supports localization and custom slugification. This package adds persisted Auto/Manual control and nested paths.
| Configuration | Behavior |
|---|---|
Default (modeToggle: false) | Editable preview follows the source until manually changed. Direct updates omitting slug preserve it; Admin may submit its preview. |
Auto (modeToggle: true) | Draft source changes regenerate the slug. Source-only updates to published documents preserve the established slug. |
Manual (modeToggle: true) | The editor controls the slug; source changes do not regenerate it. Supplied values are normalized and an empty manual value fails validation. |
Auto is read-only in the Admin. Manual-to-Auto or an explicit API slug change can change a published URL; applications own redirects. Resolve each locale's draft placeholder before publishing. Preview does not reserve uniqueness; duplicate saves fail under adapter rules.



slugField() creates a required, unique, indexed slug text field.
| Option | Default | Description |
|---|---|---|
source | Required | Document-root field path. Dot paths support named groups and objects, not arrays or blocks. |
slugify | Built-in | Optional synchronous or asynchronous slugifier. |
localized | false | Localizes the slug and, when enabled, its mode. |
modeToggle | false | Adds persisted slugMode, defaulting to Auto. |
Localized slugs require Payload localization and an effectively localized source; slug() checks at initialization, while standalone slugField() checks before preview and save.
slugField({
source: "hero.title",
localized: true,
modeToggle: true,
});
Values and modes are per locale; fallback display does not persist another translation. Uniqueness follows adapter semantics (PostgreSQL scopes localized values by locale). Override slug()'s English labels through i18n.translations.
Callbacks receive valueToSlugify, submitted data, and req. Return a non-empty URL-safe string or undefined; keep it deterministic and idempotent. Manual values also use the callback on save.
import { generateSlug, slugField } from "@klnap/payload-slug";
slugField({
source: "title",
slugify: ({ valueToSlugify }) => {
if (typeof valueToSlugify !== "string") return undefined;
const words = generateSlug(valueToSlugify).split("-");
return words.filter((word) => !["a", "an", "the"].includes(word)).join("-") || undefined;
},
});
Custom preview requires slug() and supports collections only. Its authenticated endpoint enforces collection and field read access; client data is untrusted and new-document conditional access fails closed. Global callbacks run on save, not preview.
generateSlug() can also be used independently:
import { generateSlug } from "@klnap/payload-slug";
generateSlug("Comment écrire une page", { locale: "fr" }); // "comment-ecrire-une-page"
slugField(options)slug()generateSlug(source, options?)Types: SlugFieldArgs, SlugifyFunction, SlugMode, and GenerateSlugOptions; published declarations are authoritative.
| Declared support | |
|---|---|
Payload and @payloadcms/ui | >=3.94.1 <4 |
| React and React DOM | ~19.0.9 || ~19.1.10 || ~19.2.9 || ^19.3.1 |
| Node.js | ^22.23.5 || ^24.22.3 || >=26.13.1 |
| Package format | ESM only; Admin CSS must be supported by the application bundler. |
| Database | SQLite and PostgreSQL verified; localized uniqueness follows adapter semantics. |
Collections and Globals support field saves; preview is collection-only. Next.js is not a peer dependency.
Matched PostgreSQL runs measured equal SQL counts and paired medians within 0.78 ms; this is not a zero-overhead guarantee. See performance and the playground guide.
Payload docs: localization, Admin i18n, native slug. Package: security, changelog, MIT license.
path
Stored, indexed URL paths for Payload 4 pages and posts built from a parent and a slug
75270/wk10v4
nested docs
Official plugin for nesting Payload documents inside one another
100151.9k/wk46.1kv3 v4
payload page tree
Folder-based hierarchical URL slugs with a visual page tree in the Payload admin
81536/wk19v3
payload redirect
Automatic and manual 301/302 redirect rules stored in a native Payload collection, with cycle validation
793.4k/wk0v3
localized slugs
Copies localized slug and full path values into a per-locale localizedSlugs field for multi-language Payload sites
7881/wk9v3
slug field
Configurable slug field factory for Payload collections with localized instructions and overrides
6319/wk0v4