ECHO语句中的PHP函数

ECHO语句中的PHP函数,php,html,wordpress,Php,Html,Wordpress,我正在Wordpress中使用以下功能: function wpstudio_doctype() { $content = '<!DOCTYPE html>' . "\n"; $content .= '<html ' . language_attributes() . '>'; echo apply_filters( 'wpstudio_doctype', $content ); } 函数wpstudio\u doctype(){ $content=''

我正在Wordpress中使用以下功能:

function wpstudio_doctype() {
  $content = '<!DOCTYPE html>' . "\n";
  $content .= '<html ' . language_attributes() . '>';
    echo apply_filters( 'wpstudio_doctype', $content );
}
函数wpstudio\u doctype(){
$content=''。\n;
$content.='';
echo应用过滤器('wpstudio_doctype',$content);
}
问题是函数在
标记上方显示
$content
,而不是在
HTML
标记内添加字符串

我做错了什么?

language\u attributes()
不返回属性,而是回显属性

// last line of language_attributes()
echo apply_filters( 'language_attributes', $output );
这意味着它将在组装字符串之前显示。您需要使用输出缓冲捕获该值,然后将其附加到字符串中

// Not sure if the output buffering conflicts with anything else in WordPress
function wpstudio_doctype() {
  ob_start();
  language_attributes();
  $language_attributes = ob_get_clean();

  $content = '<!DOCTYPE html>' . "\n";
  $content .= '<html ' . $language_attributes . '>';
    echo apply_filters( 'wpstudio_doctype', $content );
}
//不确定输出缓冲是否与WordPress中的其他内容冲突
函数wpstudio_doctype(){
ob_start();
语言属性();
$language_attributes=ob_get_clean();
$content=''。\n;
$content.='';
echo应用过滤器('wpstudio_doctype',$content);
}
语言属性()
不返回属性,而是回显属性

// last line of language_attributes()
echo apply_filters( 'language_attributes', $output );
这意味着它将在组装字符串之前显示。您需要使用输出缓冲捕获该值,然后将其附加到字符串中

// Not sure if the output buffering conflicts with anything else in WordPress
function wpstudio_doctype() {
  ob_start();
  language_attributes();
  $language_attributes = ob_get_clean();

  $content = '<!DOCTYPE html>' . "\n";
  $content .= '<html ' . $language_attributes . '>';
    echo apply_filters( 'wpstudio_doctype', $content );
}
//不确定输出缓冲是否与WordPress中的其他内容冲突
函数wpstudio_doctype(){
ob_start();
语言属性();
$language_attributes=ob_get_clean();
$content=''。\n;
$content.='';
echo应用过滤器('wpstudio_doctype',$content);
}

不使用输出缓冲,只需在ECHO语句中使用
get\u language\u attributes()
。在这种情况下:

function wpstudio_doctype() {
  $content = '<!DOCTYPE html>' . "\n";
  $content .= '<html ' . get_language_attributes() . '>';
    echo apply_filters( 'wpstudio_doctype', $content );
}
函数wpstudio\u doctype(){
$content=''。\n;
$content.='';
echo应用过滤器('wpstudio_doctype',$content);
}

不使用输出缓冲,只需在ECHO语句中使用
get\u language\u attributes()
。在这种情况下:

function wpstudio_doctype() {
  $content = '<!DOCTYPE html>' . "\n";
  $content .= '<html ' . get_language_attributes() . '>';
    echo apply_filters( 'wpstudio_doctype', $content );
}
函数wpstudio\u doctype(){
$content=''。\n;
$content.='';
echo应用过滤器('wpstudio_doctype',$content);
}

你好,约翰,谢谢你的回答。我明白,但举个例子会有帮助——你愿意吗?谢谢你,我现在可以解决这个问题了。嗨,约翰,这已经很好了,几分钟后就可以接受答案了,非常感谢约翰,谢谢你的回答。我明白,但举个例子会有帮助——你愿意吗?谢谢你,我现在可以解决这个问题了。嗨,约翰,这已经很好了——几分钟后我就可以接受答案了——非常感谢