如何使用某些功能显示 yoast seo 的 <meta> 值?

问题描述

我试图在不使用 get_header() 的情况下显示 yoast 显示的元数据;或 wp_head()。例如:

<Meta property="og:locale" content="es_ES" />
    <Meta property="og:type" content="article" />
    <Meta property="og:title" content="Imagen : infografía.........." />
    <Meta property="og:description" content="infografía....." />
    <Meta property="og:url" content="https://....." />

试过了,但对我不起作用:

<? PHP echo get_post_meta ($ post-> ID,'_yoast_wpSEO_Metadesc',true); ?>

解决方法

检查这个文件夹:wordpress-seo\src\presenters\open-graph 你可以看到 locale-presenter.php

找到这行代码:(应该是第 18 行)

protected $tag_format = '<meta property="og:locale" content="%s" />';

改成这样(我编辑成英文,你可以编辑你需要的语言。)

protected $tag_format = '<meta property="og:locale" content="en_US" />';