PHP变量在HTML标记之外转义
我试图显示wordpress类别的标题,我使用一个标准的woocommerce钩子,但是它的行为非常奇怪,PHP变量在html标记之外逃逸,知道为什么吗 代码如下:PHP变量在HTML标记之外转义,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我试图显示wordpress类别的标题,我使用一个标准的woocommerce钩子,但是它的行为非常奇怪,PHP变量在html标记之外逃逸,知道为什么吗 代码如下: add_action ( 'woocommerce_before_main_content', 'ebani_show_category_name' ); function ebani_show_category_name() { if ( is_product_category() ) { $categor
add_action ( 'woocommerce_before_main_content', 'ebani_show_category_name' );
function ebani_show_category_name() {
if ( is_product_category() ) {
$category_title = single_cat_title();
?>
<div class='container'>
<div class='row ebani-title'>
<div class='col-xs-12'>
<h3 class='title'><?php $category_title ?></h3>
</div>
</div>
</div>
<?php
}
}
add_action('woocommerce_在_main_内容之前,'ebani_show_category_name');
函数ebani\u show\u category\u name(){
如果(是产品类别()){
$category_title=单一类别标题();
?>
single_cat_title
title在默认情况下调用时将echo
该值。您可以通过传入false
值来使用第二个参数覆盖该值。如果不添加前缀,只需确保添加默认值'
(空字符串)作为第一个参数
更新至:
add_action ( 'woocommerce_before_main_content', 'ebani_show_category_name' );
function ebani_show_category_name() {
if ( is_product_category() ) {
$category_title = single_cat_title('', false);
?>
<div class='container'>
<div class='row ebani-title'>
<div class='col-xs-12'>
<h3 class='title'><?php echo $category_title; ?></h3>
</div>
</div>
</div>
<?php
}
}
add_action('woocommerce_在_main_内容之前,'ebani_show_category_name');
函数ebani\u show\u category\u name(){
如果(是产品类别()){
$category_title=单一类别标题(“”,false);
?>
-返回和显示行为不同。另外,
实际上没有任何作用。您缺少回音。
或
。
add_action ( 'woocommerce_before_main_content', 'ebani_show_category_name' );
function ebani_show_category_name() {
if ( is_product_category() ) {
$category_title = single_cat_title('', false);
?>
<div class='container'>
<div class='row ebani-title'>
<div class='col-xs-12'>
<h3 class='title'><?php echo $category_title; ?></h3>
</div>
</div>
</div>
<?php
}
}
add_action ( 'woocommerce_before_main_content', 'ebani_show_category_name' );
function ebani_show_category_name() {
if ( is_product_category() ) {
?>
<div class='container'>
<div class='row ebani-title'>
<div class='col-xs-12'>
<h3 class='title'><?php single_cat_title(); ?></h3>
</div>
</div>
</div>
<?php
}
}