The get_dashboard_url() WordPress PHP function retrieves the URL to the user’s dashboard.
Usage
get_dashboard_url( $user_id, $path, $scheme )
Custom Example:
$url = get_dashboard_url( 1, 'profile.php', 'https' ); echo $url;
Output:
https://example.com/wp-admin/profile.php
Parameters
$user_id
(int) (Optional) – User ID. Defaults to current user.$path
(string) (Optional) – Optional path relative to the dashboard. Use only paths known to both site and user admins. Default:''
.$scheme
(string) (Optional) – The scheme to use. Default is'admin'
, which obeysforce_ssl_admin()
andis_ssl()
.'http'
or'https'
can be passed to force those schemes. Default:'admin'
.
More information
See WordPress Developer Resources: get_dashboard_url
Examples
Get the current user’s dashboard URL
This example gets the dashboard URL for the current user and echoes it.
$current_user_id = get_current_user_id(); $dashboard_url = get_dashboard_url( $current_user_id ); echo $dashboard_url;
Get a specific user’s dashboard URL
This example gets the dashboard URL for the user with the ID of 2 and echoes it.
$user_id = 2; $dashboard_url = get_dashboard_url( $user_id ); echo $dashboard_url;
Get the dashboard URL with a custom path
This example gets the dashboard URL for the current user with the path edit.php
and echoes it.
$current_user_id = get_current_user_id(); $dashboard_url = get_dashboard_url( $current_user_id, 'edit.php' ); echo $dashboard_url;
Force HTTPS for the dashboard URL
This example gets the dashboard URL for the current user and forces the HTTPS scheme.
$current_user_id = get_current_user_id(); $dashboard_url = get_dashboard_url( $current_user_id, '', 'https' ); echo $dashboard_url;
Get the dashboard URL for a non-admin user
This example gets the dashboard URL for a non-admin user with the ID of 3 and echoes it.
$non_admin_user_id = 3; $dashboard_url = get_dashboard_url( $non_admin_user_id ); echo $dashboard_url;