-1
我目前通過一個帶有值「:section_content」的AFC將多段內容插入到我的帖子中。此外,我正在使用下面的代碼來清理我的WP帖子。我如何修改此過濾器以包含我的ACF?使用functions.php在Wordpress中過濾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;
}
?>