More in this section

Forums / Developing with Sitefinity / Delete Head tags from code

Delete Head tags from code

4 posts, 0 answered
  1. Constantin Aparaschivei
    Constantin Aparaschivei avatar
    27 posts
    Registered:
    10 Nov 2009
    26 May 2010
    Link to this post
    Hi,

    I am trying to delete Head tags for all my pages from code.
    Here is my code:

    // create a new instance of CmsManager
            CmsManager cmsManager = new CmsManager();
            // get all pages
            IList allPages = cmsManager.GetPages();

            //Response.Write("<br />Number of pages: " + allPages.Count);
            
            foreach (ICmsPage oPage in allPages) {
                
                if (oPage.PageType == CmsPageType.Normal) {

                    ICmsPage oEditPage = cmsManager.GetPage(oPage.ID, true) as ICmsPage;
                    

                    //Response.Write("<br />" + oEditPage.HeaderControls.Count.ToString() + " : " + oPage.Name + " : " + oPage.StaticUrl);

                    if (oEditPage.HeaderControls.Count > 0)
                        {
                            Telerik.Cms.Data.HeaderControl oHead = oEditPage.HeaderControls[0] as Telerik.Cms.Data.HeaderControl;
                            if (oEditPage.Keywords == string.Empty && oHead.Attributes[2].Value.ToLower() == "keywords")
                                oEditPage.Keywords = oHead.Attributes[0].Value;

                            if (oEditPage.Description == string.Empty && oHead.Attributes[2].Value.ToLower() == "description")
                                oEditPage.Description = oHead.Attributes[0].Value;

                            oEditPage.HeaderControls.Clear();
                            cmsManager.SavePage(oEditPage);

                        }  
                }
            }

    I save the keywords and description to page keywords and desc, this part works, but the Head tags are not deleted.
    What am I doing wrong ?

    I user sitefinity 3.6

    Thanks,
    Aparaschivei Constantin
  2. Siddesh Kapadi
    Siddesh Kapadi avatar
    239 posts
    Registered:
    09 Oct 2009
    27 May 2010
    Link to this post
    What is the purpose of deleting the Head tag?
  3. Constantin Aparaschivei
    Constantin Aparaschivei avatar
    27 posts
    Registered:
    10 Nov 2009
    27 May 2010
    Link to this post
    SEO purposes .. :)

    I have multiple meta keywords and meta description tags. Since I have lots of pages, manual delete will take much time, so I am trying to remove them from code.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    31 May 2010
    Link to this post
    Hello Constantin Aparaschivei,

    You can use DeleteAllHeaderControls() method of IPage object that will remove all tags.

    sample

    var m = new CmsManager();
    IPage p = m.GetPage(new Guid("fdc9bc88-546e-4c43-888f-f36ab308271f"), true);
    p.DeleteAllHeaderControls();
    m.SavePage(p);


    All the best,
    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.
Register for webinar
4 posts, 0 answered