Skip to content

Function

Sanitize a slug.

tml_sanitize_slug( string $slug )

Parameters

$slug string
The slug.

Return

string The slug.

Source

function tml_sanitize_slug( $slug ) {
    if ( ! empty( $slug ) ) {
        $slug = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $slug ) );
        $slug = trim( preg_replace( '|^/index\.php/|', '', $slug ), '/' );
    }
    return $slug;
}

Uses

Changelog

VersionDescription
7.0 Introduced.