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.


Top ↑

Parameters

$prefix string Optional
Prefix for the returned ID.

Default: ''


Top ↑

Return

string Unique ID.


Top ↑

Source

File: wp-includes/functions.php. View all references

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

Top ↑

Changelog

Changelog
Version Description
5.0.3 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.