Dynamically create Metadata from page

SHANE EBERT asked on April 3, 2017 16:09

Hello,

I have read through some threads on here and couldn't find the answer.

I want any new page's metadata title to inherit the document name. Right now it inherits the parent page title which is not good for SEO.

Example:

- Home (Page Title = Welcome to the home page)
    - Solutions (Page Title = Welcome to the home page)
        - Hardware (Page Title = Welcome to the home page)
        - Software (Page Title = Welcome to the home page)
    - Blog (Page Title = Welcome to the home page)

When I create the above pages, the metadata title just keeps inheriting the parent page's title.

When I create a "Solutions" page, it should say "Solutions" in the page title, not inherit "Welcome to the home page"

How do I fix this globally?

Correct Answer

Trevor Fayas answered on April 3, 2017 17:05

I don't like the inheritance model either, so this is what I did.

For the Master Page, i added these macros to the Page Title, Page Description, Page Keywords:

{% !string.isnullorwhitespace(MenuItemSeoTitleOverride) ? MenuItemSeoTitleOverride : DocumentName @%}

{% !string.isnullorwhitespace(Abstract)? Abstract : CMSContext.Current.Settings.GetValue("MtwDefaultMetaDescription") @%}

{% !string.isnullorwhitespace(Keywords) ? Keywords : CMSContext.Current.Settings.GetValue("mtwDefaultPageKeywords") @%}

I added to Pages the fields "MenuItemSEOTitleOverride", "Abstract" and "Keywords" which is what these reference (plus two settings keys that tehy can set the Keywords/Abstract default values globally)

This way, the Page Title will use the Document Name by Default, or the override if they provide. The description will use the 'Abstract' field of the page if provided, otherwise the site setting, and same for keywords. Works out well! Then all pages can "inherit" this macro.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on April 3, 2017 16:23

  1. In Settings>Content>Metadata make sure you don't have something set in there other than your site name, if you wish.
  2. Verify you have the Inherit checkbox checked for the individual pages metadata. Later you may choose to set this manually at which you'd uncheck the Inherit checkbox
  3. Clear your cache and verify again. Seems some of your settings may have been inadvertently changed because out of the box, the page name is automatically used for the title and prepended with the site name from #1.
0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on April 3, 2017 16:26 (last edited on December 10, 2019 02:30)

  1. Remove the inherit from Parent globally at the root level
  2. use this Macro to generate DocumentName globally {%CMSContext.CurrentDocument.DocumentName|(identity)GlobalAdministrator%}

That should do the trick for you.

2 votesVote for this answer Mark as a Correct answer

SHANE EBERT answered on April 3, 2017 17:04

Is this where I am suppose to place the Macro? Thanks

Image Text

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on April 3, 2017 17:04 (last edited on April 3, 2017 17:06)

There should be no need to use a macro, as Kentico will automatically create the title based on the document name for you. Remove those values Shane and leave them as empty values so they generate automatically.

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on April 3, 2017 17:42

@Shane - Not here but on the Properties tab of pages and going to Metadata. Actually in this you will have to use inheritance but use this macro at the root level.

@Brendon - Agree with you. Just want to be specific. In out case our content editors are smart using macros so we make things explicit to avoid any future guesses. Thanks

0 votesVote for this answer Mark as a Correct answer

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