Copied to clipboard

Flag this post as spam?

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


  • Mike Dorst 53 posts 215 karma points
    Dec 12, 2017 @ 13:37
    Mike Dorst
    0

    Hello,

    I'm trying to place some meta tags inside my templates but they don't seem to work. The tags only work then they are placed inside my master page.

    I'm trying to use these tags:

    <meta property="og:type" content=" "> 
    <meta property="og:site_name" content=" ">
    <meta property="og:title" content=" "/>
    <meta property="og:url" content=" "/>
    <meta property="og:image" content=" " />
    

    The <meta property="og:image" content=" " /> is extremely important as it gives a thumbnail when the page gets shared. However now it's just a white thumbnail as no photo is specified. I want each page to have their own photo which means in each template I need to put the meta tag.

    It only works when they're in my master page, any ideas?

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Dec 12, 2017 @ 14:13
    Alex Skrypnyk
    1

    Hi Mike

    Can you show Razor code that renders these tags? These metatags should be in the head tag of the page?

    Thanks,

    Alex

  • Mike Dorst 53 posts 215 karma points
    Dec 12, 2017 @ 14:17
    Mike Dorst
    0
    <head>
            <meta property="og:type" content="website"> 
            <meta property="og:site_name" content="sitename">
            <meta property="og:title" content="@Model.SeoTitle"/>
            <meta property="og:url" content="@Model.Content.Url"/>
            <meta property="og:image" content="@Model.Content.BackgroundImage"/>
    </head>
    

    If I debug with the facebook debugger it doesn't even show up, it only shows the code in my master page, it's like it doesn't exist on other templates.

    facebook debugger I use

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Dec 12, 2017 @ 14:50
    Alex Skrypnyk
    0

    Did you inherit your templates from the master?

  • Mike Dorst 53 posts 215 karma points
    Dec 12, 2017 @ 14:52
    Mike Dorst
    0

    Yeah.

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Dec 12, 2017 @ 15:07
    Alex Skrypnyk
    0

    what if you look at source code of the page?

    do you see tags?

  • Mike Dorst 53 posts 215 karma points
    Dec 12, 2017 @ 15:30
    Mike Dorst
    0

    Yeah I can see them, they are also filled out.

  • Mike Dorst 53 posts 215 karma points
    Dec 13, 2017 @ 07:44
    Mike Dorst
    0

    I checked again this morning. Turns out the meta tags are being rendered in the body instead of the <head> like it's in the code. I think it's because the template is being loaded into the master's page it's body.

    Any solution to this?

  • Mike Dorst 53 posts 215 karma points
    Dec 13, 2017 @ 08:31
    Mike Dorst
    101

    I managed to get it fixed with a solution on stackoverflow.

    You should use RenderSection if you want to inject something from your template into master:

    Here is an example:

    Master.cshtml:

    <!DOCTYPE html>
    <html> 
    <head>
        ...
        @RenderSection("meta", required: false)
        ...
    </head>
    <body>
        ...
        @RenderBody()
        ...
    </body>
    </html>
    

    Template.cshtml

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @section meta
    {
        <meta property="og:type" content="website"> 
        <meta property="og:site_name" content="SITENAME">
        <meta property="og:title" content="Reports"/>
        <meta property="og:url" content="www.exameple.com"/>
        <meta property="og:image" content="http://via.placeholder.com/2000x2000"/>
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft