Created
February 25, 2022 17:17
-
-
Save khleomix/a5836501af6c326df4e7642755c2321b to your computer and use it in GitHub Desktop.
Limit the content length and retain markup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Limit the content length. | |
* | |
* @author JC Palmes | |
* | |
* @param array $args Parameters include length and more. | |
* | |
* @return string The content. | |
*/ | |
function return_the_content( $args = [] ) { | |
// Set defaults. | |
$defaults = [ | |
'content' => '', | |
'char' => 500, // number of characters. | |
'more' => ' …' | |
]; | |
// Parse args. | |
$args = wp_parse_args( $args, $defaults ); | |
// Trim the content. | |
return substr( $args['content'], 0, $args['char'] ) . $args['more']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment