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 45273cf commit cff789e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.cache
node_modules
/vendor
24 changes: 24 additions & 0 deletions inc/extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,30 @@ function tni_exclude_category( $query ) {
}
add_action( 'pre_get_posts', 'tni_exclude_category' );

/**
* Modify Excerpt
* Don't strip shortcode content from excerpt
*
* @param string $text
* @return string $text
*/
function tni_excerpt_filter( $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 );
$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 Filters to `meta_content`
* Ensures that `meta_content` is return like `the_content`
Expand Down
2 changes: 1 addition & 1 deletion inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function tni_custom_excerpt( $post_id = null, $limit = null, $more = '' ) {
if( $subhead ) {
echo wp_trim_words( strip_shortcodes( $subhead ), $limit, $more );
} else {
echo wp_trim_words( strip_shortcodes( get_the_excerpt() ), $limit, $more );
echo wp_trim_words( get_the_excerpt(), $limit, $more );
}
}

Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Theme URI: https://github.com/misfist/tni-theme
Tags: Blog, Magazine
Requires at least: 4.5.0
Tested up to: 4.7.2
Version: 0.6.10
Version: 0.6.11
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -13,6 +13,9 @@ Custom theme for The New Inquiry, based on Gridbox theme.

== Changelog ==

== 0.6.11 April 18, 2017 ==
* #54 Added filter to `get_the_excerpt` to allow shortcode content in excerpt.

== 0.6.10 April 17, 2017 ==
* Minor css fix for starburst image on single magazine page on smaller width screens

Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Description: Custom theme for The New Inquiry.
Author: Pea
Author URI: https://github.com/misfist
Template: gridbox
Version: 0.6.10
Version: 0.6.11
Text Domain: tni
*/

0 comments on commit cff789e

Please sign in to comment.