Search code examples
twigadvanced-custom-fieldstimber

Out putting RAW ACF values in twig/timber unto page header for SEO purposes


So, from ACF I have created my own SEO fields in my custom WP theme, so I don't have to rely on a plugin, and I want to have the default values already filled out, so we don't always have be doing that unless for something specific - how do I out put those unto my page and insert them in the header at the same time? I have tried {{post.meta_description|raw}} and {{ function('wp_head') }} timber but it just prints it on the page, what am I missing?

Another great {{ post.tool_brand }} {{ post.tool.type}} 
for sale, {{ post.power_type }} of power with a 
competitive price {{ post. tool_price }}!

acf seo fields

{% extends "base.twig" %}

{% block content %}
    <div class="container my-4">
        <head>
            {{post.meta_description|raw}}
            {{ function('wp_head') }}
        </head>
    </div>

{% endblock %}

actual output


Solution

  • This here seems to do exactly what I wanted it to do: {{ include(template_from_string(post.meta_description)) }}

    ie: <meta name="description" content="{{ include(template_from_string(post.meta_description)) }}">