SharePoint 2010 doesn’t have a built in mechanism to handle
metadata tags for improved Search Engine Optimization (SEO). My solution for
adding metadata tags uses a combination of out-of-the-box (OOB) functionality
combined with code to allow dynamic addition of a meta title, meta description,
and meta keywords on a per page basis for content editors. I tried to keep it very
simple, easy, and extendable. There are
four major components to this solution:
1.
Set up the pages library
2.
Create a SEO user control
3.
Add the reference to the web control on the
master page
4.
Fill in the content
Pages Library Set Up
Enterprise Keywords
Enable Enterprise Keywords – In the pages library, go to
Library Settings > Enterprise Metadata and Keyword Settings. Check the top
box Add an Enterprise Keywords column to this list and enable Keyword
synchronization. This adds a column called Enterprise Keywords to the list
which is tied to the Metadata Term Store.
Out-of-the-Box Columns
The title and comments field are also used for this
solution, but they are already in the list for you. The comments column on the
pages library is the same as the description for the page. I don’t know why
Microsoft called it comments. This confuses many content editors. But they did
and there’s nothing I can do about that...
SEO User Control
Create a new user control. I called my control
SEOPageMetaTags.ascx. In addition to the standard namespaces at the top of the
SharePoint control, you also need to add the web control namespace at the top.
<%@ Register TagPrefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
Then add this code to SEOPageMetaTags.ascx:
<asp:PlaceHolder ID="MetaDescriptionHolder" runat="server">
<asp:Literal ID="metadescstart" runat="server"></asp:Literal><SharePointWebControls:FieldValue id="PageDescription" FieldName="Comments" runat="server"/><asp:Literal ID="metadescend" runat="server"></asp:Literal>
</asp:PlaceHolder>
<asp:PlaceHolder ID="MetaKeywordsHolder" runat="server">
<asp:Literal ID="metakeystart" runat="server"></asp:Literal><SharePointWebControls:FieldValue id="PageKeywords" FieldName="23f27201-bee3-471e-b2e7-b64fd8b7ca38" runat="server"/><asp:Literal ID="metakeyend" runat="server"></asp:Literal>
</asp:PlaceHolder>
It’s important to note that the metadata tags cannot be dynamically
generated on the page, like with JavaScript, as this isn’t always able to be
seen by crawlers. So, on the code behind (SEOPageMetaTags.ascx.cs), add the
following code:
///
/// This control writes out the meta description and meta keywords in the page head used for SEO.
///
public partial class SEOPageMetaTags : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
this.metadescstart.Text = "<meta name=\"description\" content=\"";
this.metadescend.Text = "\" />";
this.metakeystart.Text = "<meta name=\"keywords\" content=\"";
this.metakeyend.Text = "\" />";
}
}
Ensure the SEOPageMetaTags.ascx page is uploaded/deployed to
the location:
C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\14\TEMPLATE\CONTROLTEMPLATES
Master Page
Add this line at the top of the page so the master page
knows what control to reference:
<%@ Register TagPrefix="MyCustomStuff"
TagName="SEOPageMetaTags"
Src="~/_controltemplates/SEOPageMetaTags.ascx" %>
Add this code in the <head> under the title tag:
<!-- for SEO -->
<asp:ContentPlaceHolder id="SEOMetaTags" runat="server">
<MyCustomStuff:SEOPageMetaTags runat="server" />
</asp:ContentPlaceHolder>
Edit Page Properties
From the content editor perspective, the last step is to
fill in the information on the page properties. Just edit the properties of the
page and fill in the Title, Comments (same as page description), and the
Enterprise Keywords field.
Benefits
There are three main benefits to using the Enterprise
Keywords field in this situation.
1.
Keywords help a site’s SEO (albeit very
minimally, it still helps).
2.
Keywords are standardized since they come from
the Term Store.
3.
Enterprise Keywords show as refiners on your search
results page so this enhances your page’s findability.
You could also use the terms entered here as a means to
organize your content on your site, but that’s outside the scope of this
article. It just goes to show that using Enterprise Keywords can do a lot of
work for you that goes beyond just SEO and can help a ton especially if you
have many content editors.
Finally, this solution is easy to extend. The SEO tags
covered in this article included the Title tag, meta description, and meta
keywords. You could add other tags as well. For example, an index tag to
include the option for content editors to choose not to have a particular page
indexed or to add a page canonical url. Using the separate web control for SEO
allows you to quickly add whatever additional metadata you need.