wp_unique_id() WordPress Function

The wp_unique_id() function allows you to generate a unique ID for an object. This can be useful for creating objects that need to be identified in a database or elsewhere.

wp_unique_id( string $prefix = '' ) #

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 value: ''


Top ↑

Return

(string) Unique ID.


Top ↑

Source

File: wp-includes/functions.php

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

Top ↑

Changelog

Changelog
VersionDescription
5.0.3Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More