# _truncate_post_slug()

URL: https://chugunov.pro/api-wordpress/functions/_truncate_post_slug/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 3.6.0.

## Сигнатура

```php
_truncate_post_slug( string $slug, int $length = 200 ): string
```

## Описание

См. alsoutf8_uri_encode()

## Параметры

- `$slug` `string` — обязательный. Слаг для обрезки.
- `$length` `int` — необязательный, по умолчанию `200`. Максимальная длина слага. Значение по умолчанию 200 (символов).

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/post.php:5648`

```php
function _truncate_post_slug( $slug, $length = 200 ) {
	if ( strlen( $slug ) > $length ) {
		$decoded_slug = urldecode( $slug );
		if ( $decoded_slug === $slug ) {
			$slug = substr( $slug, 0, $length );
		} else {
			$slug = utf8_uri_encode( $decoded_slug, $length, true );
		}
	}

	return rtrim( $slug, '-' );
}
```

## История изменений

- 3.6.0 — Introduced.

## Связанные

Использует: [`utf8_uri_encode`](https://chugunov.pro/api-wordpress/functions/utf8_uri_encode/).
Используется в: [`wp_filter_wp_template_unique_post_slug`](https://chugunov.pro/api-wordpress/functions/wp_filter_wp_template_unique_post_slug/), [`wp_add_trashed_suffix_to_post_name_for_post`](https://chugunov.pro/api-wordpress/functions/wp_add_trashed_suffix_to_post_name_for_post/), [`wp_unique_post_slug`](https://chugunov.pro/api-wordpress/functions/wp_unique_post_slug/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/_truncate_post_slug/
