181,579 total views, 2 views today
A few days back one of my colleagues 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 the SharePoint Tenant admin center. Here, in this article, I will explain how to enable this.
Verify that the 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 the “Script Editor” web part is missing. Not only that we can not see also the “Content Editor” web part and many more. Please see the below screenshot:
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 is 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 the 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 on my page.
Then what to do?
Enable the custom scripting using the PowerShell script
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 Set-SPOsite "https://sprnd.sharepoint.com/sites/TestSite001" -DenyAddAndCustomizePages 0
- 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 the 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 utmost security – Microsoft does not recommend adding the custom script to the page. If we want to add any custom scripting into our SharePoint online page – we need to add these out thru the SPFx framework.
Thus, in this article, we have learned about how to enable the script editor web part in SharePoint online.
- Office 365: Getting started with SharePoint PnP PowerShell – installation
- In 2 steps convert a classic SharePoint page to modern using PnP
- Office 365: Retrieve hub sites and associated sites using PnP Powershell
- Create a modern team site using PnP PowerShell in SharePoint
- In 4 steps access SharePoint online data using postman tool
- SharePoint admin center: Learn SharePoint online administration in an hour – step by step
- SharePoint REST API: GET vs POST vs PUT vs DELETE vs PATCH
- Office 365: Understanding the hub site in SharePoint online
- 7 Ways SharePoint Can Increase Your Team Productivity