Remove Meta tag from Head dynamically using web control

David Pearson asked on April 23, 2019 21:05

My current Master loads the social media Meta tags in the header. I have a page where I want to overwrite that info using data from a Web Service API that is not hosted in Kentico.

I saw the web control headhtml that can render my new data in the head.

Page.Header.Controls.Add(new LiteralControl(HTMLCode));

How do I remove the tags I am replacing. Example remove meta tag where property = "og:title"? Is there a remove LiteralControl?

Thanks David

Recent Answers

Brenden Kehren answered on April 23, 2019 21:17

Yes, you can use:


You have to find the control first and make an instance of it before you can remove it though. Probably need some error checking in there too.

LiteralControl lit1 = (LiteralControl)Page.FindControl("lit1");  
if(lit1 != null)
2 votesVote for this answer Mark as a Correct answer

David Pearson answered on April 25, 2019 16:44

Hi Brenden,

I found the control that loads all the meta tags from the Kentico Portal Template. The control ID is called tags, it is loaded in PortalTemplate.aspx. Found og:title tag is in a string in the property Text.

Since the tags are loaded into a System.Web.UI.WebControls.Literal, I guess Kentico PortalTemplate does support editing a single tag by looping the HtmlMeta controls to find the tag you want to edit.

I am now looking at editing those tags in OnPreRender now.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.