Remove Language version of Sitecore Items

Many times you will come across scenarios where you need to remove specific language version of Sitecore items. Mostly in the multilingual websites, we do come across this kind of scenarios often and we can achieve this in multiple ways. Let’s look on How to Remove Language version of Sitecore Items in details.

Remove Specific Language Version of Sitecore Items Programmatically

The below code will remove the language versions of the root item path you specify and all the descendant Sitecore items.

public void RemoveLanguageVersion(string rootItemPath, string languageCode)
        {
            Language languageRemove = Sitecore.Globalization.Language.Parse(languageCode);
            Item rootItem = Sitecore.Context.Database.GetItem(rootItemPath, languageCode);

            if (rootItem != null)
            {
                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    //Remove language version from root item               
                    rootItem.Versions.RemoveVersion();

                    //Remove language version recursively from child items of root item
                    foreach (Item child in rootItem.Axes.GetDescendants().Where(x => x.Language == languageCode))
                    {
                        child.Versions.RemoveVersion();
                    }
                }
            }
        }
string rootItemPath = "/sitecore/content/Home";
string languageCode= "en-GB";

RemoveLanguageVersion(rootItemPath, languageCode);

The above code will remove all the en-GB language version in the home item and its descendant items recursively.

Remove a Language Version of Sitecore Item using PowerShell Script

Another best approach is to use PowerShell script to remove a specific language version. This is fast and easiest way to perform the task. The below PowerShell script will remove the en-US language version from home item and its descendants.

Step 1 : Open the PowerShell ISE console in Sitecore

Step 2: Modify the Path and language in the script for which you need to remove the language version.

Step 3: Execute the script in PowerShell ISE

$path = "master:/sitecore/content/home"
@(Get-Item $path) + (Get-ChildItem $path -Recurse) | Remove-ItemLanguage -Language "en-US"
Leave a Reply

Your email address will not be published.

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like