Advertisement
arie_cristianD

change post exceprt default length

Jan 13th, 2025
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. add_filter( 'jnews_module_excerpt', 'change_default_excerpt_length', 99, 4 );
  2.  
  3. function change_default_excerpt_length( $excerpt, $post_id, $excerpt_lenth, $except_more ) {
  4.  
  5.     if ( 20 === $excerpt_lenth ) {
  6.         $post    = get_post( $post_id );
  7.         $excerpt = $post->post_excerpt;
  8.  
  9.         if ( empty( $excerpt ) ) {
  10.             $excerpt = $post->post_content;
  11.         }
  12.  
  13.         $excerpt = preg_replace( '/\[[^\]]+\]/', '', $excerpt );
  14.         $excerpt = wp_trim_words( $excerpt, 50, $except_more );  /* change 50 as you want */
  15.     }
  16.     return $excerpt;
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement