Adding MetaDescription for Blog posts

by
Boyan Barnev
Feb 11, 2013

Adding MetaDescription tags for blogs, news, etc details view page has been a widely discussed topic in the Sitefinity community. With the following blog post we aim at demonstrating you how easy it is to achieve the desired functionality thanks to the extensibility of Sitefinity's ContentView.

For the purposes of the blog post we'll be looking at the Blogs module. As you know adding a new custom field to blog posts is as easy as making a couple of clicks in the backend, so we'll be using a simple custom field of type short text to store the desired MetaDescription.

Once you've added the custom field to blog posts you can move to the next step, which is overriding the default Telerik.Sitefinity.Modules.Blogs.Web.UI.Public.DetailPostView

inside the new custom view we're creating we can get a hold of the blog post item that will be displayed, by plugging in the InitializeControls() method and saying:

the last call we're making is to a custom method where we can retrieve the custom field value and set this data to a new MetaDescription we'll be adding in the page Header, just like this:

privatevoidAddMetaKeywordsMarkup(BlogPost item)

{

try

{

if(!string.IsNullOrEmpty(item.GetValue<String>("MetaDescription")))

{

HtmlMeta metaDescr = newHtmlMeta();

metaDescr.Name = "Keywords";

metaDescr.Content = item.GetValue<String>("MetaDescription");

this.Page.Header.Controls.Add(metaDescr);

}

}

catch(Exception )

{

}

}

where MetaDescription is the name of a custom field I've added to blog posts.

You can now tell Sitefinity to use the custom view by going to Administration->Settings->Advanced -> Blogs-> Controls->BlogsPostsFrontend->Views->DetailBlogPostsFrontend and changing the ViewType to the type of your custom view.

And there you go, you can start filling out the desired MetaDescription you want to see in your blog post's detail page.

For your convenience the custom view sample discussed in this blog post can be downloaded from here. Please do not hesitate to extend and modify it as per your requirements.

About the author

3 comments

Should be noted this should be depreciated as of 5.4. Editing in Advanced there's "MetaDescription" and "MetaKeywords" fields. Just enter the names of the custom fields that contain those pieces of data and the control will automatically render them.

So for example you can enter "Summary" into "MetaDescription" and the summary text will be in the meta tag.

Marvin Apr 23, 2013

Hi Steve,

Where in the Advanced settings can I find "MetaDescription" and "MetaKeywords" fields?

Regards,
Marvin

Nawmi Khan Oct 28, 2015

By that time when i was new blogger, I thought that setting meta description for home page is enough. lol. :P
Actually, This is more important that attract visitors to click on a site. Selecting the best meta description is essential like title and Keyword Selection .

Webinars

Tools

Progress, Telerik, Sitefinity and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries.