Skip to content

Instantly share code, notes, and snippets.

@renakdup
Last active December 12, 2022 23:59
Show Gist options
  • Select an option

  • Save renakdup/030aed2c3910b4ae3984dfb45c0ff838 to your computer and use it in GitHub Desktop.

Select an option

Save renakdup/030aed2c3910b4ae3984dfb45c0ff838 to your computer and use it in GitHub Desktop.
WordPress
<?php /**
* Function substr the excerpt by type.
*
* @param $type string Type for substr string.
* @param $post post element
*/
function rs_excerpt_length( $type, $post = false ) {
if ( ! $post ) {
global $post;
}
$string = get_the_excerpt( $post );
if ( 'news' == $type ) {
if ( strlen( $string ) > 80 ) {
$string = mb_substr( $string, 0, 80, 'UTF-8' ) . '...';
}
} elseif ( 'bignews' == $type ) {
if ( strlen( $string ) > 99 ) {
$string = mb_substr( $string, 0, 99, 'UTF-8' ) . '...';
}
}
echo $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment