Created
December 6, 2017 01:24
-
-
Save galbaras/f1d1911822091571beb9adbc81cacc80 to your computer and use it in GitHub Desktop.
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
/* 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