Roiarthur
Active member
Copy-pasting a generic script onto a production site is like putting a Lada part on a Ferrari. It fits, but it's going to smoke. For a serious board, you need to target your specific Tutorial forums (not the Off-Topic bar or the Trash can) and, more importantly, display your actual branding, not just the default XenForo variables. We are going to turn that rough draft into production-grade code.
XenForo Admins who want their guides to shine in Google with proper "TechArticle" Rich Snippets.
• List of IDs for your "Tutorial" nodes (e.g., Windows=12, Linux=14, Hardware=20)
• A direct, clean URL to your logo (square or rectangle, PNG/JPG)
Step #1 > Easy > Identifying Node IDs (Arrays)
Step #2 > Intermediate > Customizing the Code (Logo & Brand)
Explanation : Replace [10, 12, 15] with your real IDs and update the Logo URL.
Code:
<xf:if is="in_array($thread.node_id, [10, 12, 15])">
<xf:head option="ld_json_techarticle">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "TechArticle",
"headline": "{$thread.title|escape('json')}",
"image": "https://www.your-site.com/images/logo_og_image.png",
"author": {
"@type": "Person",
"name": "{$thread.User.username|escape('json')}",
"url": "{$xf.options.boardUrl}/members/{$thread.User.user_id}/"
},
"publisher": {
"@type": "Organization",
"name": "Your Board Name",
"logo": {
"@type": "ImageObject",
"url": "https://www.your-site.com/styles/default/your-style/logo.png"
}
},
"datePublished": "{{ date($thread.post_date, 'c') }}",
"dateModified": "{{ date($thread.last_post_date, 'c') }}",
"description": "{$thread.FirstPost.message|snippet(160)|strip_tags|escape('json')}"
}
</script>
</xf:head>
</xf:if>
If error : Google shows a "Missing field: image" error.
Fix : The main "image" field (line 7) must be representative of the tutorial. If you don't have a "Cover Image" addon, leave a default site image, otherwise Google will ignore the Rich Snippet.
Code:
"image": "{$thread.CoverImage ?: 'https://www.your-site.com/images/default_tuto.jpg'}",
In generic scripts, you might see {$xf.options.boardTitle}. That's risky if you ever change your board title to something like "Maintenance - My Forum". Here, we carved the brand name into the code marble. It's more pro.
I added |strip_tags in the description. If your first post starts with a Bold tag or an image, this prevents polluting the Google description with raw HTML code.
Don't forget to check the Image URL. If you put a relative URL (e.g., /images/logo.png) without the https://www.your-site.com in front, the Schema.org validator will reject you. The URL must be absolute.
Once in place, pass a tutorial URL through Google's Rich Results Test tool. If you see "TechArticle detected" in green, you win.
• Google Rich Results Test
• XenForo 2 Conditional Statements Guide
• Schema.org TechArticle Definition
• Search with Google
I adapted the script to be multi-zone (via the ID array) and bulletproof regarding URLs. Copy this into thread_view, just change the image URLs and IDs, and your SEO will take steroids. Now, go deploy.