WP add_filter使用串联和echo来调用WP函数 - WP函数仅显示为文本

时间:2014-05-19 17:04:13

标签: php wordpress add-filter

尝试通过add_filter向现有帖子添加内容。 Filter包含html和三个使用echo的WP函数调用。 Add_filter可以工作,但只将回显的函数显示为文本。 感谢任何帮助,指导或建议。

add_filter ('the_content', 'insertAuthorMetaData');
function insertAuthorMetaData($content) {
if(is_single()) {
$content.= '<div id="content" class="author-meta-info">';
$content.= '<hr/>';
$content.= '<h4 class="avatar-in-loop">';
$content.= '<h4 class="avatar-in-loop">';
$content.= '<h4 class="avatar-in-loop">';
$content.= '</h4>';
$content.= '<dl><dt></dt><dd>';
$content.= echo the_author_meta( 'description' );
$content.= ' </dd></dl><hr />';
$content.= '</div>';
 }
return $content;
}
谢谢你。 bobp

1 个答案:

答案 0 :(得分:0)

您无法在过滤器内回显。过滤器的工作是修改内容而不是输出内容。此外,您正在使用the_author_meta(),当您需要一个将返回它的函数时,它会输出元数据。您需要改为使用get_the_author_meta()

改变这个:

$content.= echo the_author_meta( 'description' );

要:

$content .= get_the_author_meta( 'description' );