-
Stefanie
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”:
ScreenshotI 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!
-
Stefanie
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!
-
Stefanie
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 -
Stefanie
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 🙂
-
Stefanie
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_ZyBut in the source-code they appear without
<p>
-tag:
https://prnt.sc/aHIVXAfJ2IWuso 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!!!
-
Stefanie
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!!!!
-
Fernando
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. -
Stefanie
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!
- You must be logged in to reply to this topic.