【发布时间】:2018-10-29 19:13:13
【问题描述】:
我正在尝试在单个产品页面上添加新标签。我的以下代码运行良好:-
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['desc_tab'] = array(
'title' => __( 'Additional Information', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
}
我想在'title'中插入一些html数据=>
例如:
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['desc_tab'] = array(
'title' => __( 'Additional Information <img src="'.$image.'"/>', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
}
以上代码输出的是完整的 html 源代码而不是图像。
任何帮助将不胜感激。
谢谢
【问题讨论】:
-
如果您查看
wp-content\plugins\woocommerce\templates\single-product\tabs\tabs.php第 37 行,esc_html()负责将 HTML 打印为选项卡标题中的文本。所以我建议你使用css添加图像。 可能有一种方法可以仅使用 PHP 来实现,但我不知道 -
嗨@RaunakGupta 感谢cmets。我有无法在 css 中添加的动态数据。喜欢
-
您也可以使用
wp_headaction 来拥有动态css
标签: php wordpress woocommerce hook-woocommerce