Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* Allow Easy Testimonials and Visual Composer shortcodes in excerpts */
add_filter( 'strip_shortcodes_tagnames', 'gbol_allow_shortcodes' );
function gbol_allow_shortcodes( $tags_to_remove ) {
$allowed_shortcodes = array( 'random_testimonial', 'single_testimonial', 'testimonials', 'testimonials_cycle', 'testimonials_grid',
'vc_row', 'vc_column', 'vc_column_text' );
foreach( $allowed_shortcodes as $tag ) {
if ( $key = array_search( $tag, $tags_to_remove ) ) {
unset( $tags_to_remove[ $key ] );
}
}
return $tags_to_remove;
}
/* Allow Easy Testimonials and Visual Composer shortcodes in excerpts used as meta descriptions */
if ( is_plugin_active( 'wordpress-seo/wp-seo.php' ) ) {
add_filter( 'wpseo_replacements', 'gbol_seo_replacements' );
function gbol_seo_replacements( $replacements ) {
global $post;
if ( ! is_singular() ) {
return $replacements;
}
$text = get_the_excerpt();
if ( strlen( $text ) < 2 ) {
$text = strip_tags( do_shortcode( $post->post_content ) );
}
$text = wp_trim_words( $text, 20, '' );
$replacements['%%excerpt%%'] = $text;
return $replacements;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment