+1-888-365-2779
Try Now
More in this section

Forums / Suggestions / Meta tags for SEO

Meta tags for SEO

7 posts, 0 answered
  1. Devin
    Devin avatar
    149 posts
    Registered:
    09 Jun 2009
    08 Jan 2010
    Link to this post
    Hi I'd like to be able to organize my head tags like this:

    <head>
    <title>title</title>
    <meta name="Description" content="..." />
    <meta name="Keywords" content="..." />
    ...
    </head>

    The key is that I would also like to be able to edit Description and Keywords for each individual page in the CMS.  I think this would be very useful for SEO purposes.  I think this is something that all Sitefinity users can benefit from.

    Thanks,
    Devin
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    30 Sep 2016
    10 Jan 2010
    Link to this post
    Hi Devin,

    The key is that I would also like to be able to edit Description and Keywords for each individual page in the CMS.

    You can do this through Sitefinity backend. Each page has a section under More Options called - Add Head tags(For all languages)
    Another option is using a simple user control and standard ASP.NET class HtmlMeta

    sample code:

    public partial class Sitefinity_UserControls_MetaTagsControl : System.Web.UI.UserControl
    {
       #region Public Properties
     
       public string MetaTagName 
       {
           get 
           {
               return metaTagName;
           }
           set 
           {
               metaTagName = value;
           }
       }
     
       public string MetaTagContent
       {
           get
           {
               return metaTagContent;
           }
           set
           {
               metaTagContent = value;
           }
       }
       #endregion
     
       protected void Page_Load(object sender, EventArgs e)
       {
           HtmlMeta metaTag = new HtmlMeta();
           metaTag.Name = this.MetaTagName;
           metaTag.Content = this.MetaTagContent;
           this.Page.Header.Controls.Add(metaTag);
     
       }
     
       private string metaTagName;
       private string metaTagContent;


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. David Pearson
    David Pearson avatar
    54 posts
    Registered:
    17 Jul 2012
    08 Mar 2010
    Link to this post
    Hi Ivan,

        Will this override the Description and keyword in SiteFinity.  I am researching an ideal to dynamically recreate the values from a database on PageLoad where we random select and reorder keywords depending on which page is being displayed. 

    Thanks,
    David
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    30 Sep 2016
    08 Mar 2010
    Link to this post
    Hello David Pearson,

    This will not override the default keys. If you want to remove any key you can use Page.Header.Controls.Remove()

    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. David Pearson
    David Pearson avatar
    54 posts
    Registered:
    17 Jul 2012
    08 Mar 2010
    Link to this post
    Thanks Ivan for the quick answer,  
        I will get the work writing the back end module  then start teh front end.
    David 
  6. Devin
    Devin avatar
    149 posts
    Registered:
    09 Jun 2009
    15 Jun 2010
    Link to this post
    Hi,
    This code will remove any existing meta tags that match the Name and add its own underneath the title tag.

    protected void Page_Load(object sender, EventArgs e)
    {
        HtmlMeta metaTag = new HtmlMeta();
        metaTag.Name = this.MetaTagName;
        metaTag.Content = this.MetaTagContent;
     
        for (int i = 0; i < Page.Header.Controls.Count; i++)
        {
            Control hm1 = Page.Header.Controls[i];
            if (hm1 is HtmlMeta && (((HtmlMeta)hm1).Name.ToLower() == this.MetaTagName.ToLower()))
            {
                Page.Header.Controls.Remove(hm1);
            }
        }
     
        this.Page.Header.Controls.AddAt(1, metaTag);
    }

    Thanks,
    Devin
  7. Allan Cadenilla
    Allan Cadenilla avatar
    1 posts
    Registered:
    30 Apr 2010
    18 Aug 2010
    Link to this post
    I accomplish this with the following.

    1) I created a custom class that inherited Telerik.Cms.Web.InternalPage
    2) Override OnPreRender

    protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
      
            int idx = 0;
            HtmlTitle title = null;
            HtmlMeta keywords = null, description = null;
      
            foreach (Control c in this.Header.Controls)
            {
                HtmlTitle t = c as HtmlTitle;
                if (t != null)
                {
                    title = t;
                }
      
                HtmlMeta m = c as HtmlMeta;
                if (m != null)
                {
                    switch (m.Name.ToLower())
                    {
                        case "keywords":
                            keywords = m;
                            break;
                        case "description":
                            description = m;
                            break;
                    }
                }
            }
      
            if (title != null)
            {
                this.Header.Controls.Remove(title);
                this.Header.Controls.AddAt(idx++, title);
            }
      
            if (keywords != null)
            {
                this.Header.Controls.Remove(keywords);
                this.Header.Controls.AddAt(idx++, keywords);
            }
      
            if (description != null)
            {
                this.Header.Controls.Remove(description);
                this.Header.Controls.AddAt(idx++, description);
            }
        }

    3) Go to ~/Sitefinity/CMSEntryPoint and substitute the inherits attribute with the custom class
Register for webinar
7 posts, 0 answered