Ich ziehe gerade mehrere Teile von Inhalt in meine Beiträge durch eine AFC mit dem Wert: "section_content". Außerdem verwende ich den unten stehenden Code, um meine WP-Posts zu bereinigen. Wie würde ich diesen Filter ändern, um auch meinen ACF einzuschließen?Der beste Weg, functions.php zu verwenden, um ACF in Wordpress zu filtern
<?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;
}
?>