diff --git a/.gitignore b/.gitignore index 2ecebfa..4d85811 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store .cache node_modules +/vendor diff --git a/inc/extras.php b/inc/extras.php index 16e89e1..3ad351a 100644 --- a/inc/extras.php +++ b/inc/extras.php @@ -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` diff --git a/inc/template-tags.php b/inc/template-tags.php index 3e2e87c..2a9dffa 100644 --- a/inc/template-tags.php +++ b/inc/template-tags.php @@ -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 ); } } diff --git a/readme.txt b/readme.txt index 6797fb7..6165ba2 100644 --- a/readme.txt +++ b/readme.txt @@ -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 @@ -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 diff --git a/style.css b/style.css index 1723de2..cd559ed 100644 --- a/style.css +++ b/style.css @@ -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 */