W3cubDocs

/WordPress

wp_basename( string $path, string $suffix = ): string

i18n-friendly version of basename().

Parameters

$pathstringrequired
A path.
$suffixstringoptional
If the filename ends in suffix this will also be cut off.

Default:''

Return

string

Source

function wp_basename( $path, $suffix = '' ) {
	return urldecode( basename( str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) ), $suffix ) );
}

Changelog

Version Description
3.1.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_basename