Duplicate page meta description when setting description from webpart

L B asked on October 2, 2018 07:25

I am trying to set the meta description of a page in a webpart by doing

Page.MetaDescription = "some value"

The page that I am doing this on has 'Page description' set as 'Inherit' in the 'Metadata' tab, however when the page loads, there are two meta descriptions in the head of the page. One with the 'Inherit' value and one with the one I set in the webpart.

Due to the complexity of the site, it is not possible to set the meta description in the 'Metadata' tab and needs to be done through a webpart.

Recent Answers

David te Kloese answered on October 2, 2018 14:24

Can you change logic from one to the other? So everything from the Web Part... and abandon the default? Or use a (custom) macro in the default behavior (depending on the complexity of your logic)

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on October 2, 2018 17:07 (last edited on October 2, 2018 17:14)

How are you setting meta value inside your web part? I am not sure it is possible because you need to access a current document from your web part something like `

protected void SetupControl()
        CurrentDocument.DocumentPageDescription = "abc"; // WONT WORK! it is inaccessible

if your DocumentPageDescription is null the hierarchy is use. You get one desciption from kentico and one your web part (because you probably setting like in ASP.net) I would create a custom macro and put into page description property. And the logic that you have in your web part - just move it in this macro. That will work!

on the other hand you may try override on prerender (try to put this in your web part):

protected override void OnPreRender(EventArgs e)

    Page.MetaDescription = "abc";
0 votesVote for this answer Mark as a Correct answer

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