Last active
August 26, 2021 01:36
-
-
Save wpexplorer/33811c988bae14e64cc83cda9d7494ec to your computer and use it in GitHub Desktop.
Text Block More Toggle - Total WP Theme
This file contains hidden or 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
// Hook into the vc_shortcode_content_filter flter to modify the vc_column_text content | |
// and covert the more tag into an actual toggle button. | |
add_filter( 'vc_shortcode_content_filter', function( $content, $shortcode ) { | |
if ( 'vc_column_text' !== $shortcode ) { | |
return $content; | |
} | |
$is_inline = vc_is_inline(); | |
$needle = $is_inline ? '<!--more-->' : '<span id="more'; | |
$pattern = $is_inline ? '#<!--more-->#' : '#<span id=\"more-\d+\"><\/span>#'; | |
if ( false !== strpos( $content, $needle ) ) { | |
$content_split = preg_split( $pattern, $content, 2, PREG_SPLIT_NO_EMPTY ); | |
if ( is_array( $content_split ) && 2 === count( $content_split ) ) { | |
$content = $content_split[0]; | |
$content .= '<button data-active-text="Read Less" aria-pressed="false">Read More</button>'; | |
$content .= '<div class="vc_column_text__more-content wpex-hidden">' . $content_split[1] . '</div>'; | |
} | |
} | |
return $content; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment