Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

New line in ACF-Settings doesn’t work with GB Headline Block

  • I have created an Element for the right sidebar. There I want to use Dynamic Data to display the content from a text field I created using ACF.

    The field type in ACF is “Text Area”. This has the setting “New Lines”:
    Screenshot

    I have used this field type many times in the past (before I switched to GB), usually it works fine and new lines are reliably converted to br.

    But now I use the GB headline-block and suddenly it doesn’t work anymore. New Lines are not converted to HTML br.

    Is this related to the GB headline block? Or have I forgotten a setting?

    URL with the right sidebar is in the private Info.

  • Hi Stefanie,

    GB’s headline block supports <br> tag, I just tested it on my site and it works.

    I don’t think there’s any special setting you need to do on GB side.

    Just make sure all the plugins are up to date.

    If that’s the case, try disabling all other plugins except GB and GP Premium to test.

    Let me know!

  • Hi Ying,

    thanks for your feedback.
    I have now disabled all plugins individually (except GP premium, GB and ACF) and tested the site again and again.
    Unfortunately none of this has changed anything 🙁

    Is it possible that GB (I use the free version) does not support this ACF function “new line”?

    Or do you have any idea what else it could be?
    Or could there be a workaround?

    Thanks!

  • hello again
    i just would like to ask, if you have read this post.

    Thanks for a short feedback.

    Best,
    Stefanie

  • Hi Stefanie,

    Sorry for the late reply.

    Is it possible that GB (I use the free version) does not support this ACF function “new line”?

    Actually, it is the reason, only the Pro version supports the new line feature, unfortunately.

    However, if you add the text with the <br> tags like below screenshot, the headline block of GB Free version should be able to pull it.
    https://www.screencast.com/t/i5aNlYCewwZ

  • Hi,

    thanks for your tip. I searched for hours to find the bug :-((
    Unfortunately i can’t use the solution with the manually inserted <br>. Because I create the site for an artist friend, she is not familiar with HTML.

    This is also the reason, why I can’t us GB Pro, it is not my site, but for an artist friend.

    Is there another way to get GB to accept the “new line”? Maybe I can build a workaround with php?

    Thank you

  • A workaround would be:

    1. Set the text area ACF field to No Formatting instead of auto adding <br> to avoid doubled <br> in the output.

    2. Add an additional CSS class to the headline block, eg. allow-br-tag.

    3. Add this PHP code, replace the text_new_line with your custom field name:

    add_filter( 'render_block', function( $block_content, $block ) {
        if (  ! empty( $block['attrs']['className'] ) && 'allow-br-tag' ===  $block['attrs']['className'] )  {
         $field_name = 'text_new_line'; // Replace with your field name
         $content = get_field($field_name);   
         $block_content = nl2br($content);
        }
    
        return $block_content;
    }, 10, 2 );

    Let me know if this works!

  • I’ve updated my answer in my last reply, hope it will work 🙂

  • Hi Ying,

    thank you so much for your help, I really appreciate it!!!

    It almost works.

    The <br>-tag is now added, that’s great 🙂

    But now the <p>-tag is gone.

    I have put 3 different headline blocks (paragraph) with dynamic data (ACF-fields):
    https://prnt.sc/Dba-ncJXv_Zy

    But in the source-code they appear without <p>-tag:
    https://prnt.sc/aHIVXAfJ2IWu

    so that it is now no longer possible to separate the individual paragraphs or style them with css.

    is it still possible to keep the <p>-tags around each item?

    Thank you very much!!!

  • Hi again,

    after I sent the post, I thought of the solution 🙂

    I changed the code to:
    $content = '<p>'.get_field($field_name).'</p>';

    and now the p-tags are added.

    Thanks a bunch for your help!!!!

  • Hi Stefanie,

    Can you try replacing the PHP snippet with this?:

    add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){
    	if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'allow-br-tag' ) !== false ) {
    		$field_name = 'text_new_line'; // Replace with your field name
            $content = get_field($field_name);   
    		return $content;
    	}
    	return $content;
    }, 10, 3);

    Replace the text_new_line with your custom field name.

  • Hi Fernando,

    thank you for your quick reply!
    Our posts overlapped. I used the code from Ying and added the <p>-tag, now it works.

    https://generate.support/topic/new-line-in-acf-settings-doesnt-work-with-gb-headline-block/#post-908

    Thank you very much!

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.