how to display user id from a function on a wordpress page

To display the user ID from a function on a WordPress page, you can follow these steps:

  1. Open your theme's functions.php file.

  2. Add the following code to create a custom function that retrieves the current user's ID:

function display_user_id() {
    $current_user = wp_get_current_user();
    return $current_user->ID;
}
  1. Save the functions.php file.

  2. Create a new page or edit an existing one where you want to display the user ID.

  3. Inside the page editor, add the following shortcode to display the user ID:

[user_id]
  1. Update or publish the page.

  2. The user ID will now be displayed on the WordPress page where you added the shortcode.

These steps will allow you to retrieve and display the user ID from a function on a WordPress page.