Let’s Talk

We would love to hear from you. Want to know more about
our services or have any questions? Say Hi!

How to Create Custom Command in Sitecore CMS?

October 06, 2023
How to Create Custom Command in Sitecore CMS?
Keyur Garala
Keyur Garala
Sitecore Certified Solutions Architect

Recently I had a requirement to create one command when the user right-clicks on a Sitecore item it should show the generate XML button on right click menu list.

  • To do that operation you need to go to the Core database in Sitecore CMS.

    Open the Content Editor and go to the given path item /sitecore/content/Applications/Content Editor/Context Menues/Default.

  • Once you open the above folder you will get many items as shown in the below screenshot.

  • Now right click on the selected folder and create an item with /sitecore/templates/System/Menus/Menu item template. and give the appropriate name which you want to show on your menu. For Ex. I want for generate XML so I’ll set as “Generate XML”. As shown in screenshot below.

  • Now navigate to Message Field and set your command Method as shown in the below screenshot.


    In the above screenshot, the Message value meaning is as below


    item is used for to indicate the item

    generatexml is a custom method that I created in my code.

    id=$Target is used for the argument of the custom method which

  • Now go to your project and create Class File into your project and inherit Sitecore.Shell.Framework.Commands.Command To your class. and create two methods and writedown your logic to Gerate XML into it. As mentioned in the below screenshot.

  • Now go to the root folder and open the Sitecore.Commands.config from App_Config/Sitecore/CMS.Core folder. And add the below command at the last of the command to your Sitecore.Commands.config. As shown below screenshot.

    <command name="item:generatexml" type="HG.Explore.Indesign.ContextMenu.XmlMenuItem, HG.Explore.Indesign" />

    The name should be the same as set on the Sitecore Item Message Field just remove the round braces from that.

    Type value should be your class name and Namespace.


The conclusion is once you do that you will be able to see the menu item on the CMS Side.