Skip to content

Turn more button into read more toggle

red round round round container

https://gist.github.com/wpexplorer/33811c988bae14e64cc83cda9d7494ec

// 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 );

Dieser Beitrag hat 0 Kommentare

Schreibe einen Kommentar

Deine E-Mail wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

An den Anfang scrollen