Created
July 16, 2024 17:31
-
-
Save Pross/f7cc2fed494c557a0f6d7b7d239a3f6c to your computer and use it in GitHub Desktop.
Basic <!--more--> implementation for text module in Beaver Builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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