我现在正在通过一个取值为"section_content“的自动取款机把多个内容放入我的帖子中。此外,我使用下面的代码来清理我的可湿性粉剂帖子。如何修改此筛选器以包括我的ACF?
<?php
/**
* Clean posts from inline styling and unnecessary tags
*/
add_filter( 'the_content', 'clean_post_content' );
function clean_post_content($content) {
if ( is_single() ) {
$patterns = array(
'/(<[^>]+) style=".*?"/i', // Remove inline styling
'/<\/?font[^>]*>/', // Remove font tag
'/<(p|span)>(?>\s+| |(?R))*<\/\1>/', // Empty p, span (font tags already removed)
'/(<h[1-6]>[^<]*)<\/?strong>(.*?<\/h[1-6]>)/', // h1-6
);
$replacements = array(
'$1',
'',
'',
'$1$2'
);
$old_content = '';
while ($old_content != $content) {
$old_content = $content;
$content = preg_replace($patterns, $replacements, $content);
}
}
return $content;
}
?>发布于 2016-07-22 17:49:18
我想你可以使用ACF Filters。我通常挂接到acf/format_value,以便在打印之前清理或修改我的自定义字段值。
您甚至可以仅挂钩到某些字段类型,例如:
function acf_brand_trademark( $value, $post_id, $field ) {
$value = preg_replace( '/Brand /', 'Brand<sup>™</sup> ', $value );
return $value;
}
add_filter('acf/format_value/type=textarea', 'acf_brand_trademark', 10, 3);
add_filter('acf/format_value/type=text', 'acf_brand_trademark', 10, 3);希望这能有所帮助!
https://stackoverflow.com/questions/38377681
复制相似问题