Skip to content

Instantly share code, notes, and snippets.

@mrwweb
Created March 9, 2017 17:34
Show Gist options
  • Save mrwweb/0235f18da595eca8351e7c51512d274d to your computer and use it in GitHub Desktop.
Save mrwweb/0235f18da595eca8351e7c51512d274d to your computer and use it in GitHub Desktop.
A custom plugin to limit the length of excerpts *only* when they appear in Feature a Page Widget. (https://wordpress.org/plugins/feature-a-page-widget/) Save this file as `truncate-fpw-excerpt.php` and then place it in `/wp-content/mu-plugins/`. You may need to create this directory if it doesn't exist yet.
<?php
/*
Plugin Name: Truncate Feature a Page Widget Excerpt
Description: Limits excerpt to 30 words. Ends cut-off excerpts with "..."
Version: 1.0
Author: Mark Root-Wiley
Author URI: https://mrwweb.com
*/
add_filter( 'fpw_excerpt', 'wp8887975_trim_fpw_excerpt' );
function wp8887975_trim_fpw_excerpt( $excerpt ) {
$excerpt = wp_trim_words( $excerpt, 30, '&hellip;' );
return $excerpt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment