Skip to content

Instantly share code, notes, and snippets.

@galbaras
Created December 6, 2017 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galbaras/f1d1911822091571beb9adbc81cacc80 to your computer and use it in GitHub Desktop.
Save galbaras/f1d1911822091571beb9adbc81cacc80 to your computer and use it in GitHub Desktop.
/* 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