前言
筛选在元素设置中选择“自定义”HTML 标签时所允许的 HTML 标签列表。确保自定义标签被正确清理。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/allowed_html_tags', function( $allowed_html_tags ) {
// Add 'marquee' to the list of allowed tags
$allowed_html_tags[] = 'marquee';
return $allowed_html_tags;
} );
参数
$allowed_html_tags(array):允许的 HTML 标签名称数组。
示例代码
筛选返回值
add_filter( 'bricks/allowed_html_tags', function( $allowed_html_tags ) {
// Add 'marquee' to the list of allowed tags
$allowed_html_tags[] = 'marquee';
return $allowed_html_tags;
} );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/allowed_html_tags', function( $value, $allowed_html_tags ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。