【问题标题】:Out putting RAW ACF values in twig/timber unto page header for SEO purposes出于 SEO 目的,将 RAW ACF 值放在树枝/木材中的页面标题中
【发布时间】:2021-11-20 21:46:38
【问题描述】:

所以,从 ACF,我在自定义 WP 主题中创建了自己的 SEO 字段,因此我不必依赖插件,并且我希望已经填写默认值,所以我们并不总是除非有特定的事情,否则我一直在这样做 - 我如何将它们放到我的页面中并同时将它们插入标题中?我试过{{post.meta_description|raw}} 和{{ function('wp_head') }} timber 但它只是打印在页面上,我错过了什么?

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

{% extends "base.twig" %}

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

{% endblock %}

【问题讨论】:

  • @DarkBee 我不确定它是否确实如此,或者我可能不理解某些东西,希望解决方案比这一切更容易吗?
  • 您显示的输出存储在数据库中,默认情况下,twig 不会解析存储在(字符串)变量中的“模板”,因此您需要告诉 twig,解析存储在变量post.meta_description

标签: twig advanced-custom-fields timber


【解决方案1】:

这似乎完全符合我的要求:{{ include(template_from_string(post.meta_description)) }}

即:&lt;meta name="description" content="{{ include(template_from_string(post.meta_description)) }}"&gt;

【讨论】:

    猜你喜欢
    • 2020-06-19
    • 2016-01-15
    • 1970-01-01
    • 1970-01-01
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    相关资源
    最近更新 更多