If you want to make a URL relative from the WordPress root, you can use the following WordPress function.

<?php

$full_url = "https://intelyblog.com/how-to-programmatically-add-a-wordpress-admin-user-using-functions-php/";

$relative_to_wordpress = wp_make_link_relative($full_url);

echo $relative_to_wordpress;

?>

Result: /how-to-programmatically-add-a-wordpress-admin-user-using-functions-php/

That’s all! Happy coding!