Skip to content

Commit

Permalink
#54 Added filter to get_the_excerpt
Browse files Browse the repository at this point in the history
#54 Added filter to `get_the_excerpt` to allow shortcode content in excerpt.
  • Loading branch information
misfist committed Apr 18, 2017
1 parent 5e26ed8 commit 71b37e7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions inc/extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,25 +286,30 @@ function tni_exclude_category( $query ) {
* Modify Excerpt
* Don't strip shortcode content from excerpt
*
* @since 0.6.11
*
* @link https://developer.wordpress.org/reference/hooks/get_the_excerpt/
*
* @param string $text
* @return string $text
*/
function tni_excerpt_filter( $text = '' ) {
$limit = 55;
function tni_filter_excerpt( $text = '' ) {
$limit = 55;
$raw_excerpt = $text;
if ( '' == $text ) {

$text = get_the_content( '' );
$text = strip_shortcodes( $text );
$text = do_shortcode( $text );
$text = apply_filters( 'the_content', $text );
$text = str_replace( ']]>', ']]>', $text );
$excerpt_length = apply_filters( 'excerpt_length', $limit );
//$excerpt_more = apply_filters( 'excerpt_more', ' ' . '[...]' );
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt );
}
remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
add_filter( 'get_the_excerpt', 'tni_excerpt_filter' );
add_filter( 'get_the_excerpt', 'tni_filter_excerpt' );

/**
* Add Filters to `meta_content`
Expand Down

0 comments on commit 71b37e7

Please sign in to comment.