I want to remove empty tags around shortcodes in WYSIWYG field.
Based on this working code for the regular WP WYSIWYG, I tried to create an equivalent for the ACF WYSIWYG, but it doesn’t work. It renders shortcodes directly in the editor after saving the post 🙁
function remove_empty_tags_around_shortcodes_acf_wysiwyg( $value, $post_id, $field ) {
$tags = array(
'<p>[' => '[',
']</p>' => ']',
']<br>' => ']',
']<br />' => ']'
);
$content = apply_filters('the_content',$value);
$content = strtr($content, $tags);
return $content;
}
add_filter('acf/load_value/type=wysiwyg', 'remove_empty_tags_around_shortcodes_acf_wysiwyg', 10, 3);
Can anyone help?
change
function remove_empty_tags_around_shortcodes_acf_wysiwyg( $value, $post_id, $field ) {
to
function remove_empty_tags_around_shortcodes_acf_wysiwyg( $value ) {
and
add_filter('acf/load_value/type=wysiwyg', 'remove_empty_tags_around_shortcodes_acf_wysiwyg', 10, 1);
to
add_filter('acf_the_content', 'remove_empty_tags_around_shortcodes_acf_wysiwyg', 10, 1);
See the notes here https://www.advancedcustomfields.com/resources/wysiwyg-editor/