Blog Archive

Cristian M. Zaragoza Gómez

HTML tag language attribute in SharePoint 2010 for SEO-aware webs

2011-07-29 15:59:00 by Cristian M. Zaragoza Gómez

If observe the HTML tag in a Sharepoint page using the developer tool of Internet Explorer, we will see something like this:




We can see the <html> tag has a property with a lang=”en-us” attribute which indicates that the language page is in American English. How can Sharepoint know the language page? Let’s see the code line of the master page in which we are “painting” the <html> tag:


<html xmlns="" lang="<%$Resources:wss,language_value %>" dir="<%$Resources:wss,multipages_direction_dir_value %>" runat="server" __expr-val-dir="ltr">


We must realize that we are assigning a code fragment to the lang attribute, which basically determines the language package we have activated and gives back the corresponding language code. The question is that if we are interested in changing that language we are showing,for any reason, we can modify the lang attribute.

Therefore, taking into account that the <html> tag is inside an ASP.NET master page with the runat="server", and for this reason we can deal with it as it is a control device to modify its properties, we can use the following code to edit the lang attribute:

For Each control As Control In Me.Page.Master.Controls
            If String.Equals(control.GetType.ToString, "System.Web.UI.HtmlControls.HtmlGenericControl") AndAlso _
               String.Equals(DirectCast(control, HtmlGenericControl).TagName, "html") Then
                DirectCast(control, HtmlGenericControl).Attributes("lang") = "xx-xx"
            End If

What we are doing is searching through all the master page controls that one which belongs to the “HtmlGenericControl” type and, in addition, its tag name should be “html”. In this way we can make sure that we are dealing with the control we want to. Once we have the control, we can simply modify the lang attribute.

I hope this is useful. See you later! Guiño


No Comments
Leave a Comment
(*) Title:
(*) Name:
Your URL:
(*) Comments:
Follow us on: