I’ve searched for hours looking for a way to insert “Read More” tag for pages, not blog pages or archives. I see discussions going back 8 years about this issue but still nothing has changed or did I miss something?
The <!--more-->
tag only works in the WordPress content area, not in BB layouts. BB replaces the content area with whatever modules are added, the text module literally just spits out what you add to it, it is not part of the standard WP content area and is not part of the WP loop.
I realized the WP tag is an issue for BB but why hasn’t something has been done to get this feature built in? From what I can see, this problem has existed for years. “Read More” is a critical capability. I see there are some paid plugins claiming to work so if they can do it why can’t BB add it to the product?
Like I said. When you are using a text module, BB just prints the output of that text module
When you add the more tag to WP post content and view that page, you are in the wp loop, wp uses the content filters and thats where the tag is processed.
I wouldn’t use the WP tag and develop a different method. Other’s have done it.
Here you go, should get you started. Uses the standard WP more tag
add_filter( 'fl_builder_render_module_content', function( $content, $module ) {
if ( $module instanceof FLRichTextModule && strstr( $content, '<!--more' ) ) {
$content = str_replace( '<div class="fl-rich-text">', '', $content );
$content = preg_replace( '#</div>$#', '', $content );
$parts = get_extended( $content );
$main = balanceTags( $parts['main'], true );
$main = preg_replace( '/<([^<\/>]*)>([\s]*?|(?R))<\/\1>/imsU', '', $main );
$more_text = $parts['more_text'] ? $parts['more_text'] : 'Read More...';
$main .= sprintf( '<a class="read-more-link-%s" href="#">%s</a><script>jQuery(".read-more-link-%s").on("click", function(e){e.preventDefault();jQuery(".read-more-%s").fadeIn()})</script>', $module->node, $more_text, $module->node, $module->node );
$extended = balanceTags( $parts['extended'], true );
$extended = preg_replace( '/<([^<\/>]*)>([\s]*?|(?R))<\/\1>/imsU', '', $extended );
$extended = sprintf( '<div style="display:none" class="read-more-%s">%s</div>', $module->node, $extended );
$content = sprintf( '<div class="fl-rich-text">%s%s</div>', $main, $extended );
return $content;
}
return $content;
}, 10, 2 );
Thank you very much.
Do I add script to the BB global javascript or …?
Thanks for your help, much appreciated.
Jay
It is not javascript
Add it to your child theme functions.php file
I’ve added the code to the child theme function file but it doesn’t work.
-
Adding text to a page (not blog post), the “Insert Read More tag” is not visible on the editor tool bar and instead I used the “Text” area and inserted the tag. In the editor “Visual” view I can see the “------- MORE --------” tag and text below it.
-
From the “Visual” tab of the editor there is no “Read More” button visible but if I click where the hidden text is, it becomes visible (while editing the BB page).
-
When I save and publish the page, the text above the “more” area is visible but under the more tag is hidden but there is no “read more” button or link.
-
Clicking on empty space for the “more” area it doesn’t expose the text either.
You never asked for the WP text editor button. The following will add it back.
remove_filter( 'mce_buttons', 'FLBuilder::editor_buttons' );
The reason the more link was blank was because I assumed you were doing something like <!--more Read More... -->
Anyway, I fixed the code to say Read More… by default now.
I didn’t know the !–more Read More… – was an option. This ia great. Thanks for all of your help.
This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.