Add WPAutoP

Correct paragraph issues with ACF WYSIWYG fields in GenerateBlocks

If you’re using an Advanced Custom Fields WYSIWYG and displaying it using a GenerateBlocks Headline block, you might have noticed that it strips your text of any paragraphs.

I don’t fully understand why, but I know it has something to do with WPAutoP, and Tom from GenerateBlocks has shared some code with me to fix this issue.

You can copy the PHP below and paste it either into a Code Snippet or inside of the Functions.php file in your child theme (read more on adding PHP).

add_filter( 'generateblocks_dynamic_content_output', function( $output, $attributes ) {
	if ( isset( $attributes['dynamicContentType'] ) && 'post-meta' === $attributes['dynamicContentType'] ) {
		$id = isset( $attributes['postId'] ) ? $attributes['postId'] : get_the_ID();
		$custom_field = get_field_object( $attributes['metaFieldName'], $id );
 
		if ( isset( $custom_field['type'] ) && 'wysiwyg' === $custom_field['type'] ) {
			$output = wpautop( $output );
		}
	}
 
	return $output;
}, 10, 2 );

Once this code is on your website, the WYSIWYG content should display in paragraphs correctly.

Kyle Van Deusen

Co-founder of The Admin Bar Community, owner of OGAL Web Design, and a GeneratePress & GenerateBlocks enthusiast.

For official support, please visit the forums for GeneratePress or GenerateBlocks

If you're looking to have a website built with GeneratePress & GenerateBlocks, then visit my agency website.

Leave a Comment