Surendra Sharma

Surendra Sharma

Search This Blog

Sunday, April 30, 2023

5 ways to set Alt text for images in Sitecore

Introduction:

Alt text is a crucial part of website accessibility and SEO, as it provides a description of the content of an image to people with visual impairments. Sitecore provides various ways to set Alt text for images, from manual to automatic using AI. In this article, we will explore the different ways to set Alt text for images in Sitecore, including manual, via C# code, via PowerShell, using Config setting "Media.AutoSetAlt", and AI with sample code.

Manual:

The most basic and straightforward way to set Alt text for images in Sitecore is to do it manually. You can do this by uploading the image to the Media Library and setting the Alt text manually in the "Alt" field of the image. When you click on the image, you will see the editing options on the right-hand side of the screen. In the "Alt" field, add a description of the image, which will be read by screen readers.

AI with image tagging:

This approach uses Azure Cognitive Services' Computer Vision API to generate a description of an image and sets it as the alt text of the corresponding image item in Sitecore using C# code.

The steps involved in this approach include installing the Azure Cognitive Services Computer Vision NuGet package, creating an instance of the ComputerVisionClient class with your subscription key and endpoint, and calling the AnalyzeImageAsync method to get a description of the image.

The retrieved description is then set as the alt text field of the image item in Sitecore using the Sitecore API.

This approach can be useful when you have a large number of images in Sitecore that require alt text descriptions, as it can automate the process of generating descriptions and setting them for each image item.

However, it's important to note that the accuracy of the generated descriptions may vary depending on the image and the complexity of its content. Therefore, it's recommended to review and potentially modify the descriptions as needed to ensure they accurately reflect the content of the image.

Via C# code:

If you want to set Alt text for images programmatically, you can do so using C# code. You can use the Sitecore API to set the Alt text for an image. Here is an example code snippet:

 

using Sitecore.Data.Items;

using Sitecore.Resources.Media;

 

// Get the MediaItem for the image

var mediaItem = (MediaItem)Sitecore.Context.Database.GetItem("/sitecore/media library/Images/my-image");

 

// Save the changes

mediaItem.Editing.BeginEdit();

mediaItem.Alt = "This is my image";

mediaItem.Editing.EndEdit();

 

In the code above, we first get the MediaItem for the image we want to set the Alt text for. Then, we set the Alt text using the "Alt" property of the media item. Finally, we save the changes by calling "BeginEdit" and "EndEdit" on the media item.

Via PowerShell:

Sitecore PowerShell is a powerful tool that allows you to automate tasks in Sitecore. You can use PowerShell to set Alt text for images in bulk. Here is an example script that sets the Alt text for all images in a folder:

$imagesToBeUpdated = "/sitecore/media library/2023 Images"

$images = Get-ChildItem -Path $imagesToBeUpdated -Language * -Recurse |

Where-Object { ($_.Fields["Alt"] -ne $null) -and ($_.Fields["Alt"].Value -eq '' -or $_.Fields["Alt"].Value -eq '$name') }

 

$images |

    ForEach-Object {

        write-host "Updating Alt text for - " $_.Name

        $_.Editing.BeginEdit()

        $_["Alt"] = $_.Name

        $_.Editing.EndEdit() | Out-Null

    }

 

In the script above, we first get the folder we want to set the Alt text for. Then, we loop through all the media items in the folder using the "Get-ChildItem". For each media item, we check if the Alt text is empty, and if it is, we set the Alt text using the "BeginEdit" and "EndEdit" methods.

Using Config setting "Media.AutoSetAlt":

Sitecore also provides an automatic way to set Alt text for images using a configuration setting called "Media.AutoSetAlt". When this setting is enabled, Sitecore will automatically set the Alt text for an image using its file name. Here's how to enable this setting:

1.      Open the Sitecore.config file located in the \App_Config\Include\ folder

2.      Search for the "Media.AutoSetAlt" setting in the file.

3.  <setting name="Media.AutoSetAlt" value="true" />

 

3.     Save the Sitecore.config file.

Now, when you upload an image to the Media Library, Sitecore will automatically set the Alt text using the file name. For example, if you upload an image named "my-image.jpg", Sitecore will set the Alt text to "my-image".

Conclusion:

In conclusion, setting Alt text for images is essential for website accessibility and SEO. Sitecore provides various ways to set Alt text for images, from manual to automatic using AI. Each method has its own advantages and disadvantages, and you should choose the method that best fits your needs. Manual and C# code methods are suitable for setting Alt text for individual images, while Sitecore's with AI solution provides an advanced way to set Alt text by analyzing the image. Whereas PowerShell is suitable for bulk operations. Finally, using the "Media.AutoSetAlt" setting is suitable for setting Alt text automatically based on the file name. By using these methods, you can ensure that all images on your website have appropriate Alt text and are accessible to everyone.

Here is video for the same



Sunday, April 23, 2023

Sitecore Technology Radar

Sitecore is a leading digital experience platform that empowers organizations to deliver personalized and engaging digital experiences to their customers. As with any technology, there are constantly new tools and trends emerging in the Sitecore ecosystem that can impact an organization's digital strategy. A Sitecore technology radar can help organizations stay informed about these changes and make informed decisions about which technologies to adopt, trial, assess, or hold. 

Sitecore technology radar typically consists of four rings, each representing a different level of adoption and maturity for a particular technology: Adopt, Trial, Assess, and Hold. Let's explore each of these rings in more detail. 

 Sitecore Technology Radar

Adopt 

In the Adopt ring, technologies are widely adopted and proven to be effective in the Sitecore ecosystem. These technologies are generally stable and reliable, and organizations can confidently use them to support their business needs. Some examples of technologies in the Adopt ring for Sitecore include: 

  • Sitecore Experience Platform (XP) 
  • Content Hub DAM 
  • Sitecore JSS (JavaScript Services) 

Trial 

In the Trial ring, technologies are emerging and have shown potential, but are not yet widely adopted. Organizations may experiment with these technologies to gain experience and assess their potential value. Some examples of technologies in the Trial ring for Sitecore include: 

  • Sitecore XM Cloud 
  • Sitecore SXA (Sitecore Experience Accelerator) 
  • Sitecore CDP 

Assess 

In the Assess ring, technologies are on the horizon and are being evaluated for their potential value. These technologies are not yet fully understood, and organizations need to carefully evaluate their potential benefits and risks before making any decisions. Some examples of technologies in the Assess ring for Sitecore include: 

  • OrderCloud 
  • Sitecore Search 

Hold 

In the Hold ring, technologies are no longer recommended for use. These are technologies that have become outdated, are no longer supported, or have been replaced by newer technologies. Some examples of technologies in the Hold ring for Sitecore include: 

  • Sitecore Commerce 
  • Web Forms for Marketers (WFFM) 
  • Sitecore Experience Database (xDB) 


By regularly reviewing and updating their Sitecore technology radar, organizations can stay ahead of emerging trends and make informed decisions about which technologies to adopt, trial, assess, or hold. This can help organizations to optimize their Sitecore digital experience and stay competitive in the rapidly evolving digital landscape. 

Here is the Youtube video for the same!!!





Monday, April 10, 2023

Reasons to move from Sitecore XP to Sitecore XM Cloud

As businesses continue to evolve and innovate, their digital strategies and web development needs must also adapt. In recent years, we have seen a shift towards using cloud-based platforms for web development and deployment, and the adoption of JavaScript-based frameworks for front-end development. Sitecore, a leading digital experience platform, has embraced this trend with the introduction of Sitecore XM Cloud and Next.js. 

If you currently have a Sitecore XP MVC-based website, you may be wondering why you should consider moving to Sitecore XM Cloud and Next.js. Today, we will explore some of the key benefits of making the move, and why it could be the right choice for your business. 

Here are some of the key reasons why businesses may want to consider moving from Sitecore XP to Sitecore XM Cloud: 

  • .NET Framework
  • Scalability
  • Improved Performance
  • Reduced Costs
  • Flexibility
  • Security
  • Faster time to market
  • Global reach
  • Ease of use
  • Improved collaboration
  • Continuous innovation
  • Better customer experiences
  • Reduced complexity
  • Lower total cost of ownership .NET Framework Since the .NET framework is on its way out, it would be wise to steer clear of it and redirect attention towards Javascript frameworks. As cloud is the future, it's a favorable time to start investing and focusing on cloud-based technologies. Scalability One of the main benefits of Sitecore XM Cloud is its scalability. Sitecore XM Cloud is a cloud-based platform that is designed to handle large amounts of traffic and data, making it ideal for businesses that need to scale quickly to meet demand. With Sitecore XM Cloud, businesses can easily scale up or down as needed, without having to worry about infrastructure management or capacity planning. Improved Performance Sitecore XM Cloud also offers improved performance compared to Sitecore XP. Sitecore XM Cloud is designed for high availability and reliability, ensuring that your website or application is always up and running. Additionally, Sitecore XM Cloud includes a range of performance optimization tools, such as Content Delivery Networks (CDNs) and caching, which can improve page load times and reduce server response times. Reduced Costs Another benefit of Sitecore XM Cloud is that it can help businesses reduce costs. Sitecore XM Cloud is a fully managed service, which means that businesses don't need to worry about infrastructure management or maintenance. This can significantly reduce the costs associated with managing and maintaining an on-premises infrastructure. Flexibility Sitecore XM Cloud also offers greater flexibility than Sitecore XP. Sitecore XM Cloud is a headless platform, which means that it can be integrated with a wide range of front-end frameworks, allowing developers to use the tools and frameworks that they are most comfortable with. This can help businesses build highly customized, tailored solutions for their clients. Security Sitecore XM Cloud provides enhanced security features, such as automatic updates and patches, proactive monitoring, and 24/7 security operations support. This can help businesses ensure that their websites and applications are protected against cyber threats. Faster time to market Sitecore XM Cloud includes a range of pre-built templates and components, which can help businesses get their websites and applications up and running quickly. This can significantly reduce the time to market for new digital experiences. Global reach Sitecore XM Cloud is designed to support businesses with a global presence. It includes a range of features, such as geo-targeting, multi-language support, and local hosting options, which can help businesses deliver personalized, localized experiences to users around the world. Ease of use Sitecore XM Cloud includes a user-friendly interface that makes it easy for businesses to manage their digital experiences. It also includes a range of tools for content management, analytics, and personalization, which can help businesses improve the efficiency and effectiveness of their digital operations. Improved collaboration Sitecore XM Cloud includes collaboration tools that can help teams work together more effectively. Continuous innovation Sitecore XM Cloud is a cloud-based platform that is continually updated with new features and capabilities. This means that businesses can benefit from the latest innovations and best practices without having to worry about upgrading their infrastructure or software. Better customer experiences Sitecore XM Cloud is designed to help businesses deliver exceptional customer experiences across all channels and touchpoints. By leveraging the power of Sitecore XM Cloud, businesses can create personalized, targeted experiences that engage and delight their users, driving loyalty and advocacy. Reduced complexity Sitecore XM Cloud is designed to simplify the digital experience management process, making it easier for businesses to manage and optimize their websites and applications. By reducing complexity, businesses can free up resources to focus on other areas of their business, such as innovation, product development, and customer engagement. Lower total cost of ownership Sitecore XM Cloud can help businesses reduce their total cost of ownership by eliminating the need for on-premises infrastructure and reducing maintenance and management costs. Additionally, Sitecore XM Cloud includes flexible pricing options, which can help businesses tailor their costs to their specific needs and usage patterns. Conclusion There are many reasons why businesses may want to consider moving from Sitecore XP to Sitecore XM Cloud. By leveraging the scalability, performance, security, flexibility, collaboration, insights, innovation, customer experience, and simplicity of Sitecore XM Cloud, businesses can achieve their digital transformation goals and drive growth and success in the digital age.

Here is video for the same


Monday, April 3, 2023

8 ways to Find and Replace text in Sitecore

The utilization of the find and replace technique is immensely valuable for both editors and developers who seek to modify individual or multiple pieces of content within a Sitecore instance.

To facilitate this process, here is my recorded Youtube video that shows 8 potential approaches to conducting find and replace operations in Sitecore.