XenForo Instructions for Creating OG:IMAGE tags

micke

Registered
Compatible XF Versions2.2

Here's how to create og:image tag by finding the file in the post, and automatically selecting the largest image file size.
Open the thread_view template, find the following code:
PHP:
<xf:macro template="metadata_macros" name="metadata"
    arg-description="{$fpSnippet}"
    arg-shareUrl="{{ link('canonical:threads', $thread) }}"
    arg-canonicalUrl="{{ link('canonical:threads', $thread, {'page': $page}) }}" />

Replace to:
PHP:
<xf:set var="$og_image" value="0" />
<xf:set var="$file_size" value="0" />
<xf:foreach loop="$thread.FirstPost.Attachments" value="$attach"> 
    <xf:if is="$attach.thumbnail_url && ($attach.file_size > $file_size)">
        <xf:set var="$og_image" value="{{ link('canonical:attachments', $attach) }}" />
        <xf:set var="$file_size" value="{$attach.file_size}" />
    </xf:if>
</xf:foreach>
<xf:if is="$og_image">
    <xf:macro template="metadata_macros" name="metadata"
        arg-imageUrl="{$og_image}"
        arg-description="{$fpSnippet}"
        arg-shareUrl="{{ link('canonical:threads', $thread) }}"
        arg-canonicalUrl="{{ link('canonical:threads', $thread, {'page': $page}) }}" />
<xf:else/>
<xf:macro template="metadata_macros" name="metadata"
    arg-description="{$fpSnippet}"
    arg-shareUrl="{{ link('canonical:threads', $thread) }}"
    arg-canonicalUrl="{{ link('canonical:threads', $thread, {'page': $page}) }}" />
</xf:if>
 
  • Tags
    og:image og:image tags
  • Back
    Top Bottom