1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.5 How do I add some HTML into the <head> section from a main template?

Discussion in 'Styling and Customization Questions' started by Stuart Wright, Oct 20, 2015.

  1. Stuart Wright

    Stuart Wright Well-Known Member

    I need to add some code, specifically
    <meta property="og:image:secure_url" content="@imagePath/editorial/products/{$feature.url}" />
    into the head area of our custom review pages.
    I guess it's the equivalent of adding custom HTML to the head section of the forum_list page.
    How do I do that, please?
  2. Chris D

    Chris D XenForo Developer Staff Member

    The forum_list template already does this, you can do the same thing. This should work in any template:
    <xen:container var="$head.image_secure_url"><meta property="og:image:secure_url" content="@imagePath/editorial/products/{$feature.url}" /></xen:container>
    The key thing here is the $head variable. It is an array, and it is looped through in the container header. You can add whatever keys you like to the $head variable, in this case, I've called the key "image_secure_url" and given it a value containing the meta property code you want.
  3. Stuart Wright

    Stuart Wright Well-Known Member

    Oh this is awesome. I love Xenforo. So many hidden gems. Thanks, Chris.
  4. Stuart Wright

    Stuart Wright Well-Known Member

    @Chris D what if I want to override the standard og:image with the main image from the content?
  5. Chris D

    Chris D XenForo Developer Staff Member

    Sort of similarly, that happens like this:

    <xen:container var="$head.openGraph">
        <xen:include template="open_graph_meta">
            <xen:set var="$url">{xen:link 'canonical:forums'}</xen:set>
            <xen:set var="$title">{$xenOptions.boardTitle}</xen:set>
            <xen:set var="$description">{$xenOptions.boardDescription}</xen:set>
            <xen:set var="$ogType">website</xen:set>
    That's from the forum_list template. We don't actually include this automatically in every page though.

    Theoretically, you could overwrite the container var value by defining it in the template with the same key, e.g. $head.openGraph and whatever you want the value to be, e.g:

    <xen:container var="$head.openGraph"><!-- Removed og meta data --></xen:container>
    That would effectively comment the meta data out if it already exists, I believe.
    Stuart Wright likes this.

Share This Page