How To: Add Meta Tags to Pages in MOSS 2007
Hi,
Here's a nice one to jump start the week: Meta Tags (or in particular "Meta Tags in MOSS 2007"). As you may have noticed, MOSS isn't too friendly with adding/changing Meta Tags for its Aspx pages. Not such a big issue if you're implementing an inner organizational portal but once you think about the Web – you might consider tagging your pages in ways to reflect in search engines. Well, after researching this issue a bit, I've found a nice little way to work around this but I've also came across a set of articles called "Death of a Meta Tag". I feel like I need to refer to those articles before talking about the possible solution since this could be a whole bunch of work for nothing. It looks like you could spend your time improving your search rank in much more useful ways than this. In other words, Microsoft probably gave up on Tags for a reason and you might as well be educated about it before implement Meta Tags on your own. Here are the links to the articles:
Ok. If you're still into developing it – that's not a hard task at all. Here's what you can do:
- Start with creating a new Rendering control. This control will be rendered in the header so this is where we'll add the logic and support for Meta Tags. You can find a very detailed information about this issue in the following MSDN article.
The main thing you'll have to do is to override the RenderControl method and use the following code (example for Keywords):
writer.Write("<meta name=\"keywords\" content=\"" + YOUR_KEYWORDS_HERE + "\" />");
Now, since you're implementing this control - you can decide whether to use hard coded Meta Tags or read them from a DB/File.
- Open the relevant Master Page and add a new Content Place Holder (for example: <asp:ContentPlaceHolder id="PlaceHolderMetaTags" runat="server"/>) in the <head> section.
- The last thing is to add the new control you've created into the Place Holder in the following manner:
<PublishingWebControls:EditModePanel runat="server" id="metadataSection" SuppressTag="true" PageDisplayMode="Display">
<MyControls: MyMetadataFieldControl FieldName="MyMetadata" runat="server"></Mytag:HeadMetadataFieldControl>
</PublishingWebControls:EditModePanel>
That's it. Looks like a pretty easy task after all. However, if you had a brief look in the articles mentioned here - you would know no to expect it to affect the search ranking too much…
Bye,
Adir Ron.