Title: wp_generate_uuid4
Published: December 6, 2016
Last modified: February 24, 2026

---

# wp_generate_uuid4(): string

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#wp--skip-link--target)

Generates a random UUID (version 4).

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#return)󠁿

 string UUID.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#source)󠁿

    ```php
    function wp_generate_uuid4() {
    	return sprintf(
    		'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
    		mt_rand( 0, 0xffff ),
    		mt_rand( 0, 0xffff ),
    		mt_rand( 0, 0xffff ),
    		mt_rand( 0, 0x0fff ) | 0x4000,
    		mt_rand( 0, 0x3fff ) | 0x8000,
    		mt_rand( 0, 0xffff ),
    		mt_rand( 0, 0xffff ),
    		mt_rand( 0, 0xffff )
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/functions.php#L7958)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/functions.php#L7958-L7970)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Application_Passwords::create_new_application_password()](https://developer.wordpress.org/reference/classes/wp_application_passwords/create_new_application_password/)`wp-includes/class-wp-application-passwords.php` |

Creates a new application password.

  | 
| [WP_Application_Passwords::get_user_application_passwords()](https://developer.wordpress.org/reference/classes/wp_application_passwords/get_user_application_passwords/)`wp-includes/class-wp-application-passwords.php` |

Gets a user’s application passwords.

  | 
| [WP_Customize_Manager::establish_loaded_changeset()](https://developer.wordpress.org/reference/classes/wp_customize_manager/establish_loaded_changeset/)`wp-includes/class-wp-customize-manager.php` |

Establishes the loaded changeset.

  | 
| [WP_Customize_Manager::_publish_changeset_values()](https://developer.wordpress.org/reference/classes/wp_customize_manager/_publish_changeset_values/)`wp-includes/class-wp-customize-manager.php` |

Publishes the values of a changeset.

  | 
| [WP_Customize_Manager::save_changeset_post()](https://developer.wordpress.org/reference/classes/wp_customize_manager/save_changeset_post/)`wp-includes/class-wp-customize-manager.php` |

Saves the post for the loaded changeset.

  | 
| [WP_Customize_Manager::save()](https://developer.wordpress.org/reference/classes/wp_customize_manager/save/)`wp-includes/class-wp-customize-manager.php` |

Handles customize_save WP Ajax request to save/update a changeset.

  | 
| [WP_Customize_Manager::__construct()](https://developer.wordpress.org/reference/classes/wp_customize_manager/__construct/)`wp-includes/class-wp-customize-manager.php` |

Constructor.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#comment-content-6070)
 2.    [thanasisxan](https://profiles.wordpress.org/thanasisxan/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/#comment-6070)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_generate_uuid4%2F%23comment-6070)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_generate_uuid4%2F%23comment-6070)
 4.  It should be noted that using this function to generate uuid’s **WILL** lead to
     collisions by creating duplicates, I found out not the fun way.
 5.  The function `mt_rand()` used will always produce the same sequence of random 
     numbers given the same seed. So every time a seed is repeated, the same exact 
     UUID is generated.
 6.  To get around this, you would need to seed it using something else for example:
 7.      ```php
         mt_srand( crc32( serialize( array( microtime( true ), 'USER_IP', 'ETC' ) ) ) );
         ```
     
 8.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_generate_uuid4%2F%3Freplytocom%3D6070%23feedback-editor-6070)
 9.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/?output_format=md#comment-content-5371)
 10.   [Philipp Stracker](https://profiles.wordpress.org/strackerphil-1/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/wp_generate_uuid4/#comment-5371)
 11. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_generate_uuid4%2F%23comment-5371)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_generate_uuid4%2F%23comment-5371)
 12. Sample result: 11223344-5566-7788-99AA-BBCCDDEEFF00
 13. A UUID represents a 128-bit value (16 bytes): It contains four 4-byte digits that
     are represented in hex notation, and are segmented by 4 “-” symbols. The total
     length is 36 characters.
 14. The “-” symbols appear after byte 4, byte 6, byte 8 and after byte 10.
 15. Because it’s a hex-value, a UUID should be treated in a case-insensitive manner:
     `
     11223344-5566-7788-99AA-BBCCDDEEFF00` is identical to `11223344-5566-7788-99aa-
     bbccddeeff00`
 16. This function always returns a lower-case string.
 17. To get a 32-character string (same as MD5) you could use:
 18.     ```php
         <?php
         $uuid36 = wp_generate_uuid4();             // a938e855-483e-48c7-9b98-f41e90511f77
         $uuid32 = str_replace( '-', '', $uuid36 ); // a938e855483e48c79b98f41e90511f77
         ```
     
 19.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_generate_uuid4%2F%3Freplytocom%3D5371%23feedback-editor-5371)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_generate_uuid4%2F)
before being able to contribute a note or feedback.