Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lee Bainbrigge 4 posts 75 karma points
    Apr 13, 2021 @ 11:22
    Lee Bainbrigge
    0

    SEO Dynamic title using articleTags

    Hi I am new to Umbraco, However I have an existing site I am trying to improve for SEO.

    The dynamic article pages have been setup where dynamic articleTags pages use the same page title so aren't listed by the search engines.

    I am trying to reference the articleTags and populate the title, therefore create unique titles for each dynamic page created where:

    https://domainname.com/article?tag=test1

    Would produce:

    In my main template I have the following but I must be missing something as it doesn't output the articleTags used in the page.

    @if (Model.HasValue("articleTags"))
    {
        <title>@home.Sitename | @Model.Name  | @(Model.Value<string>("articleTags"))</title>
    }
    else if (Model.HasProperty("metaTitle") && Model.HasValue("metaTitle"))
    {
        <title>@home.Sitename | @Model.Name  | @(Model.Value<string>("metaTitle"))</title>
    }
    else
    {
        <title>@home.Sitename | @Model.Name  | @(home.Value<string>("defaultMetaTitle"))</title>
    }
    

    Help Appreciated. Regards Lee

  • Brendan Rice 538 posts 1102 karma points
    Apr 13, 2021 @ 22:46
    Brendan Rice
    1

    Hi Lee,

    according to the docs the tags can be referened like this:

    @if(Model.GetProperty("articleTags") !=null){
        <ul>
            @foreach(var tag in Model.GetProperty("articleTags").Value<IEnumerable<string>>()){
                <li>@tag</li>
            }
        </ul>
    }
    

    https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Tags/

  • Lee Bainbrigge 4 posts 75 karma points
    Apr 14, 2021 @ 08:46
    Lee Bainbrigge
    1

    Thanks Brendan, Yes got there in the end also here's the code snippet that works for my title, but absolutely not !=null was key in the if statement:

    @if (articleTag != null)
    {
        <title>@home.Sitename | @Model.Name  | @articleTag</title>
    
    }
    else if (Model.HasProperty("metaTitle") && Model.HasValue("metaTitle"))
    {
        <title>@home.Sitename | @Model.Name  | @(Model.Value<string>("metaTitle"))</title>
    }
    else
    {
        <title>@home.Sitename | @Model.Name  | @(home.Value<string>("defaultMetaTitle"))</title>
    }
    

    Thanks for your support, regards Lee

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies