Skip to main content
Topic: How to add the 1.1.9 Structured Meta Data to your custom theme (Read 714 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How to add the 1.1.9 Structured Meta Data to your custom theme

ElkArte 1.1.9 added support for structured meta data (features -> general in the ACP).  This will produce Open Graph and Schema.org data for various pages of your site.  This data is used by search engines and when a page is shared on a social media site and may help with SEO

To use the new data, which is available in $context,  you need to add a new calls in your index.template.php file.

First add the following in the same area where the template is outputting <meta style tags (robots, description, viewport) which is up in the page top section.
Code: [Select]
	// If we have any Open Graph data, here is where is inserted.
if (!empty($context['open_graph']))
{
echo '
' .implode("\n\t", $context['open_graph']);
}

Next in the template_html_below() function, after the line theme()->template_javascript(true); add the following:
Code: [Select]
	// Schema microdata about the organization?
if (!empty($context['smd_site']))
{
echo '
<script type="application/ld+json">
', json_encode($context['smd_site'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), '
</script>';
}

// Schema microdata about the post?
if (!empty($context['smd_article']))
{
echo '
<script type="application/ld+json">
', json_encode($context['smd_article'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), '
</script>';
}
This will output the data at the end of the page.