Wordpress 如何在描述元标记中打印摘录

Wordpress 如何在描述元标记中打印摘录,wordpress,Wordpress,我只需要一种打印方法: <meta property="og:description" content="This in the content" /> 我使用了以下代码: <meta property="og:description" content="<?php $tags = array("<p>", "</p>"); $myExcerpt = str_replace($tags, "", the_excerpt()); echo g

我只需要一种打印方法:

<meta property="og:description" content="This in the content" />
我使用了以下代码:

<meta property="og:description" content="<?php 

$tags = array("<p>", "</p>");
$myExcerpt = str_replace($tags, "", the_excerpt());

echo get_the_excerpt(); ?>" />
<meta property="og:description" content="<?php 
$tags = array("<p>", "</p>");
$myExcerpt = str_replace($tags, "", the_excerpt());
echo $myExcerpt; ?>" />
但它打印的是:

<meta property="og:description" content="<p>Content of my plugin. No related posts.</p>
This is the content." />
<meta property="og:description" content="<p>Content of my plugin. No related posts.</p>" />
<meta property="og:description" content="<p>Content of my plugin. No related posts.</p>" />
如果改用此代码:

    <meta property="og:description" content="<?php    
    echo get_the_excerpt();  ?>" />
它打印这个:

<meta property="og:description" content="<p>Content of my plugin. No related posts.</p>
This is the content." />
<meta property="og:description" content="<p>Content of my plugin. No related posts.</p>" />
<meta property="og:description" content="<p>Content of my plugin. No related posts.</p>" />
如果我使用此代码:

<meta property="og:description" content="<?php 

$tags = array("<p>", "</p>");
$myExcerpt = str_replace($tags, "", the_excerpt());

echo get_the_excerpt(); ?>" />
<meta property="og:description" content="<?php 
$tags = array("<p>", "</p>");
$myExcerpt = str_replace($tags, "", the_excerpt());
echo $myExcerpt; ?>" />
它打印这个:

<meta property="og:description" content="<p>Content of my plugin. No related posts.</p>
This is the content." />
<meta property="og:description" content="<p>Content of my plugin. No related posts.</p>" />
<meta property="og:description" content="<p>Content of my plugin. No related posts.</p>" />
您应该使用返回摘录的,而不是重复摘录的_摘录:

<meta property="og:description" content="<?php 

$tags = array("<p>", "</p>");
$myExcerpt = str_replace($tags, "", get_the_excerpt());

echo $myExcerpt; ?>" />

一体式seo包插件可以将内容插入meta标签,但这并不意味着它会成为页面/帖子的内容、描述或摘录。您需要回显用于存储该信息的var seo包的值。

我已经在许多网站上使用了此代码片段,它运行良好

<meta property="og:description" content='<?php $myExcerpt = strip_tags(get_the_excerpt()); echo $myExcerpt; ?>' />

刚刚完成,但它打印:我的插件的内容。没有相关员额。这不是内容,它正在打印当前页面的实际摘录,也就是说,它应该做什么。您确定在该页上定义了摘录吗?你在哪里定义这是内容?我什么都没做。但是我正在使用一个SEO包,它在描述元标签中正确地打印内容。你想要内容还是摘录?这是两件不同的事情。阅读更多有关摘录的信息。您需要定义一个,以便显示一个。否则,您将需要编写一个函数来动态设置/创建一个。我希望在描述元标记中打印“全部在一个seo包中”的内容。刚刚完成,但它会打印以下内容:您是将此代码添加到循环中,还是在循环外?我有上面的代码在循环中,它正在工作。我在我的facebook标签功能中使用了这些代码:添加动作“wp\u head”,“我的facebook\u标签”;