Quick Tips - Custom Modules - Changing the Meta Description of a Page
NOTE: the concepts presented in this article are now considered obsolete possibly because better alternatives are available.
In an earlier article I showed you how to change the title of the page from within a custom module. From a Search Engine Optimization perspective, you may also want to update the meta tag for the description of the document. Search engines use this to index your document, and quite often the contents of this meta tag are displayed as the description of the page in the search results on many search engines. Setting the meta description of the page is just as easy as the setting the title, although you may not discover how to do it in IntelliSense directly.
To set the meta description of the page in a custom module, you access the Pageview property of the ContentModule class, the base class for all your custom modules. The Pageview property has a Meta property which has a MetaTags collection property. By indexing this collection using "Description" as the key, you can change the meta description of the page:
[AddInName("YourModuleName")] public class Frontend : ContentModule { public override string GetContent() { // Other code here to create HTML Pageview.Meta.MetaTags["Description"] = "Your custom description here"; // Other code here to return the HTML } }
When rendered in the browser, your description ends up as a <meta /> element in the <head /> of the page. Here's an example of the <meta /> tag from the page you're currently reading:
<meta name="Description" content="This quick tip shows you how to change the meta description of a page from a custom module." />