ACF apparently expands shortcodes before returning content, which means if you attempt to run it through the_content
filter, any line breaks will get hit by wpautop
. We fought and fought and fought, moving filter orders around, removing filters, etc., and finally decided to not fight WordPress, but instead change Gravity Forms.
Below is a simple filter that collapses all whitespace including line breaks, tabs and regular spaces, and just replaces it with a single space. This should preserve whatever Gravity Forms is doing, and also address WordPress’s later escaping.
add_filter(
"gform_shortcode_form",
static function ($shortcode_string, $attributes, $content) {
return trim(preg_replace('/\s+/', ' ', $shortcode_string));
},
10,
3
);