Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将woocommerce_页面_标题存储在变量中并在woocommerce中显示_Php_Wordpress_Templates_Woocommerce_Page Title - Fatal编程技术网

Php 将woocommerce_页面_标题存储在变量中并在woocommerce中显示

Php 将woocommerce_页面_标题存储在变量中并在woocommerce中显示,php,wordpress,templates,woocommerce,page-title,Php,Wordpress,Templates,Woocommerce,Page Title,我想在类别图像上显示页面标题。我复制了这个代码 <h1 class="page-title"><?php woocommerce_page_title(); ?></h1> 从“template archive product.php”到“woocommerce hook.php”,如下所示: $html .= '<h1 class="page-title">'<?php woocommerce_page_title(); ?>'

我想在类别图像上显示页面标题。我复制了这个代码

<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>

从“template archive product.php”到“woocommerce hook.php”,如下所示:

$html .= '<h1 class="page-title">'<?php woocommerce_page_title(); ?>'</h1>';
$html.='';
现在标题没有出现。当我检查开发工具时,标题就像一条html注释

<h1 class="page-title"><!--?php woocommerce_page_title(); ?--></h1>

如果有人能帮助我,那就太好了。

试试下面的代码:

$html .= '<h1 class="page-title">' . woocommerce_page_title() .'</h1>';
$html.=''。woocommerce_page_title()';
而不是:

$html .= '<h1 class="page-title">'<?php woocommerce_page_title(); ?>'</h1>';
$html.='';
默认情况下会回显模板,如…中所示,但有一个可选参数可用于返回数据,而不是回显数据。为此,您需要将此参数从(默认)
true
转换为
false

当您需要在变量中设置此数据时,这非常有用,就像您正在尝试做的那样。因此,功能代码应该有所不同:

$html .= '<h1 class="page-title">' . woocommerce_page_title( false ); . '</h1>';
$html.=''。第页标题(假);“;
测试和工作

或者,您也可以使用php缓冲函数,通过以下方式获得相同的结果:

ob_start();
?>
<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
<?php
$html .= ob_get_clean();
ob_start();
?>

但是没有回声不是意味着这个标题会直接打印出来,而忽略=标记吗?