Slug Field
A text input that automatically formats its value as a URL-safe slug. Can mirror another ACF field in real time — type a title and the slug updates instantly. Supports hyphen or underscore separators, optional uppercase, max length, and a uniqueness warning.
Slug Field requires the Extra Fields for ACF Pro license.
Settings
| Setting | Default | Options | Description |
|---|---|---|---|
| Sync From | (empty) | ACF field name | Name of another ACF field to mirror as a slug in real time (e.g. title). |
| Allow Uppercase | false | on/off | Allow uppercase letters. Off = forces lowercase. |
| Separator | - | - · _ | Character used to replace spaces and special characters. |
| Max Length | 0 | Integer | Maximum character count. 0 = unlimited. |
| Uniqueness Check | false | on/off | Warn the editor if the entered slug already exists in the database. |
Return values
Returns the slug string exactly as stored.
$slug = get_field('product_slug');
// "my-awesome-product"
$slug = get_field('db_key'); // separator: _, allow_uppercase: true
// "My_Awesome_Key"
Usage
Building a custom permalink
$post_slug = get_field('custom_slug');
if ($post_slug) {
$base_url = home_url('/products/');
$url = $base_url . rawurlencode($post_slug) . '/';
echo '<a href="' . esc_url($url) . '">' . esc_html(get_the_title()) . '</a>';
}
Generating a CSS class or HTML ID
$section_slug = get_field('section_id');
if ($section_slug) {
echo '<section id="' . esc_attr($section_slug) . '" class="section">';
}
Rewrite rule from ACF slug
$custom_base = get_field('archive_slug', 'option');
if ($custom_base) {
add_rewrite_rule(
$custom_base . '/([^/]+)/?$',
'index.php?post_type=product&name=$matches[1]',
'top'
);
}
Using in a WP_Query
$slug = get_field('linked_category_slug');
if ($slug) {
$term = get_term_by('slug', $slug, 'category');
if ($term) {
$posts = get_posts([
'category' => $term->term_id,
]);
}
}
The Sync From setting takes the ACF field name (not the label). Find it in the field's settings under "Field Name" — it's the snake_case identifier like product_title.