Is there a way to show the user name when user logins to team site it should Show welcome the user with current user name
Welcome CurrentUser
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityThere is no OOB way to do that, you can use JSOM to achieve it.
An example for you:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
var loginName = "";
var userid = _spPageContextInfo.userId;
GetCurrentUser();
function GetCurrentUser() {
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
var requestHeaders = { "accept" : "application/json;odata=verbose" };
$.ajax({
url : requestUri,
contentType : "application/json;odata=verbose",
headers : requestHeaders,
success : onSuccess,
error : onError
});
}
function onSuccess(data, request) {
var loginName = data.d.Title;
// alert("Hello " + loginName);
// to set the "hello username" into the page
document.getElementById("welcomediv").innerHTML = "Welcome " + loginName;
}
function onError(error) {
alert(error);
}
</script>
<div id="welcomediv">
If you want to show it on a modern page, you need to install modern script editor web part, then add the above code into it.
About installing modern script editor web part, you can refer to:
SharePoint | Online | Best Practice | install Modern Script Editor Web Part for SharePoint Online Modern Site.
It already displays the current user's photo in the upper right hand corner. If you want a customized welcome message, there is no oob method, but this can be done via code, either an SPFx web part or perhaps a custom SPFx extension.
I am not sure, there is OOB method available to get that. But you can use JSOM to get user display name and show it on page. Below link may help to get started: https://stackoverflow.com/questions/20981226/sharepoint-2013-get-current-user-using-javascript
If you are using classic experience, you can add Script editor webpart to add script on page.
If you are using Modern experience, you will need to either use SPFX or react-script-editor webpart available on Github.