Skip to content

Instantly share code, notes, and snippets.

@Pross
Created July 16, 2024 17:31
Show Gist options
  • Save Pross/f7cc2fed494c557a0f6d7b7d239a3f6c to your computer and use it in GitHub Desktop.
Save Pross/f7cc2fed494c557a0f6d7b7d239a3f6c to your computer and use it in GitHub Desktop.
Basic <!--more--> implementation for text module in Beaver Builder
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 );
$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, $parts['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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment