Created
July 24, 2022 19:20
-
-
Save frontend-coder/e0006bb41b9c9330252ad0ce8c008933 to your computer and use it in GitHub Desktop.
43. Кастомний exerpt #wordpress
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
function domain_trim_excerpt($length) { | |
global $post; | |
$explicit_excerpt = $post->post_excerpt; | |
if ( '' == $explicit_excerpt ) { | |
$text = get_the_content(''); | |
$text = apply_filters('the_content', $text); | |
$text = str_replace(']]>', ']]>', $text); | |
} | |
else { | |
$text = apply_filters('the_content', $explicit_excerpt); | |
} | |
$text = strip_shortcodes( $text ); // optional | |
$text = strip_tags($text); | |
$excerpt_length = $length; | |
$words = explode(' ', $text, $excerpt_length + 1); | |
if (count($words)> $excerpt_length) { | |
array_pop($words); | |
array_push($words, '[…]'); | |
$text = implode(' ', $words); | |
$text = apply_filters('the_excerpt',$text); | |
} | |
return $text; | |
} |
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 echo wp_kses_post( domain_trim_excerpt(25) ); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment