Few days back one of my colleague reported me that he is not finding the script editor web part in SharePoint online site. After some analysis we got to know that in SharePoint online site script editor web part is not available by default. In order to make it available we need to enable the custom script from SharePoint Tenant admin center. Here, in this article I will explain how to enable this.
Verify that script editor web part is not available by default:
Navigate to the edit your web part page – > Insert -> Web Part -> Categories ->Media and Content
Here we can see that “Script Editor” web part is missing. Not only that we can not see also “Content Editor” web part and many more. Please see the below screen shot:
Now go to your tenant setting page thru this url
Note: Here “sprnd” is my tenant name, you need to pass your tenant name.
Now see the “Custom Script” section by default both the radio button are selected as prevent – this is the default behavior and due to this script editor and content editor web part is missing from SharePoint online page.
- Prevent users from running custom script on personal sites.
- Prevent users from running custom script on self-service created sites)
Now select to allow users to run custom script for both the radio button as like below:
- Allow users from running custom script on personal sites.
- Allow users from running custom script on self-service created sites)
Now click on ok and once you save it , this may take 24 hours to reflect the changes – this is what the message says from Microsoft but this was not correct at least for us. We had waited for around 3 days but still didn’t see the script editor web part in my page.
Then what to do?
To overcome this issue run the below PowerShell script – this will immediately add the script editor and content editor web part in the web part category. This is the reason to write and share this article.
$adminUserID=”youradminaccount@< sprnd.onmicrosoft.com >”
$userCredential = Get-Credential -UserName $adminUserID -Message “Enter password”
Connect-SPOService -Url https://sprnd-admin.sharepoint.com/ -Credential $userCredential
- It should be your tenant domain account and your actual site.
- Here I have used my test trial tenant site.
- In Connect-SPOService pass your tenant admin url
- In Set-SPOsite pass the site url where you want to add the script editor web part.
- If your tenant admin account has MFA (multi factor authentication) enabled , you cannot execute this – to execute this script use the account which does not have MFA enabled.
Verify that script editor web part is available after executing the PowerShell Script:
After executing the above script – immediately come to the same page – wow we can see the script editor, content editor and many other web parts those were not there before the script execution under “Categories”:
Why Microsoft does not allow to add the script editor web part by default?
Considering the up most security – Microsoft does not recommend to add the custom script into the page. If we want to add any custom scripting in to our SharePoint online page – we need to add these out thru the SPFx framework.