How to detect Page Editor mode in Sitecore through code

f you are a Sitecore developer then definitely in many instances you would need to show or hide some components in the Page Editor mode. So How to detect Page Editor mode in Sitecore through code?

There are many ways to detect the page editor mode in Sitecore using Javascript, with the help of cookies, query string etc. But let us look into the best approach to check the page editor mode using server side and client site.

How to detect Page Editor mode in Sitecore Programmatically?

The best and simple approach is to get the information using Sitecore.Context.PageMode. If the site is being viewed in the PageEditor mode then you could easily enable or disable the components with the help of a condition.

if (Sitecore.Context.PageMode.IsPageEditor)
// Write your logic here
// Logic If its not a page editor mode

if (Sitecore.Context.PageMode.IsPageEditorEditing) –To check if it is Page Editor mode
if (Sitecore.Context.PageMode.IsNormal) – To check if it is normal page use
if (Sitecore.Context.PageMode.IsPreview) – To check if it is preview mode use

Other Sitecore PageModes

  • IsPageEditorClassic
  • IsPageEditorDesigning
  • IsPageEditorEditing
  • IsPageEditorNavigating

Detecting Sitecore PageEditor Mode In JavaScript

In case if you would like to detect PageEditor mode in client side using the JavScript, then below code should help you in detecting if the user is using the Page editor mode or normal mode.

var isPageEditor = function(){
    return !!(Sitecore && Sitecore.PageModes && Sitecore.PageModes.PageEditor);

if(isPageEditor()) {
    // Write your logic here

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like
XOR in Python

XOR in Python

XOR Operator in Python is also known as “exclusive or”  that compares two binary numbers bitwise if two bits are…
How To

How to configure Git proxy?

If you are working in the corporate company all the internet requests usually goes through the corporate firewall.…