Skip to content

Instantly share code, notes, and snippets.

@igorveremsky
Last active October 24, 2017 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorveremsky/375a7bc21f5631b76d2abeedec84b22f to your computer and use it in GitHub Desktop.
Save igorveremsky/375a7bc21f5631b76d2abeedec84b22f to your computer and use it in GitHub Desktop.
Custom Excerpt for Wordpress
<?php
/**
* Excerpt content
*/
function iv_excerpt($excerpt_length, $added)
{
$text = apply_filters( 'the_excerpt', get_the_excerpt() );
$text = preg_replace('/\[.+\]/', '', $text );
$chars_text = strlen($text);
$text = $text." ";
$text = substr($text,0,$excerpt_length);
$text = substr($text,0,strrpos($text,' '));
$text = $text.$added;
$text = apply_filters('the_content', $text);
$text = str_replace(array('[…]','[...]', '<p>', '</p>'), '', $text );
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment