php - 在 WooCommerce 产品描述周围添加一个 div
问题描述
我使用以下方法在单个产品页面上移动了产品摘要:
add_action( 'woocommerce_single_product_summary', 'custom_the_content', 35 );
function custom_the_content() {
echo the_content();
}
现在我需要将内容包装在一个div中,所以我尝试了
echo '<div class="mydiv">' . the_content() . '</div>';
但这导致内容没有被 div 包裹,而是 div 是空的,只是添加到 html 中,内容如下。如何将内容包装到我的 div 中?
解决方案
您需要使用 get_the_content(); 而不是 the_content(); 如果你想自己回应它。
the_content() 已经在内部回显,因此您将无法包装它。
如果您的页面内容包含应由 wp 内部过滤器(如简码)处理的数据,那么您应该使用如下内容:
ob_start();
the_content();
$content= ob_get_clean();
echo '<div class="mydiv">' . $content. '</div>';
推荐阅读
- python - 有没有办法在 Python 中定义比较函数到 issubset
- c++ - 复制列表初始化?为什么会这样编译?
- swiftui - 如何避免致命错误:SwiftUI 中没有 ... 类型的 ObservableObject?
- bash - 在 bash 中使用 diff 创建和检查 Apache2 服务的哈希时出现问题
- marshmallow - 如何将 schema.dump 功能与采摘的 data_key 一起使用?
- python - Python:正则表达式搜索“Mozilla”,但如果字符串还包含“iPhone”则忽略匹配
- regex - grep 匹配区分 1 和 -1
- python - 我如何在字典列表中找到下一个最小数字
- python - 使用 tkinter 进行多项选择测验
- java - 将自定义属性添加到现有视图