W3cubDocs

/WordPress

wp_unique_id( string $prefix = ): string

Gets unique ID.

Description

This is a PHP implementation of Underscore’s uniqueId method. A static variable contains an integer that is incremented with each call. This number is returned with the optional prefix. As such the returned value is not universally unique, but it is unique across the life of the PHP process.

Parameters

$prefixstringoptional
Prefix for the returned ID.

Default:''

Return

string Unique ID.

Source

function wp_unique_id( $prefix = '' ) {
	static $id_counter = 0;
	return $prefix . (string) ++$id_counter;
}

Changelog

Version Description
5.0.3 Introduced.

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