我正在使用 ACF 并为我的产品设置了一个名为product_title
.
我正在尝试使用我的 functions.php 文件中的 WooCommerce 挂钩在我的产品页面上显示此自定义字段。
function hom_add_product_header()
{
$product_title = the_field('product_title');
?>
<h1><?php echo $product_title; ?></h1>
<?php
}
add_filter('woocommerce_single_product_summary', 'hom_add_product_header', 5);
但是当我查看呈现的页面时,product_title
它呈现在空<h1></h1>
标签之外!
我也尝试过像这样的输出缓冲......
function hom_add_product_header()
{
# Add the start
ob_start();
$product_title = the_field('product_title');
?>
<h1><?php echo $product_title; ?></h1>
<?php
# Fetch the cache
$data = ob_get_contents();
# End and clear the buffer
ob_end_clean();
# Send data back for render
return $data;
}
add_filter('woocommerce_single_product_summary', 'hom_add_product_header', 5);
但是使用此代码根本不会显示任何内容!
为什么我的内容没有在 HTML 标签内呈现?