Advertisement
arie_cristianD

Change module post excerpt to 50 characters only

Jan 29th, 2024 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. /**
  2.  * Change post exceprt moodule to 50 word
  3.  * This code will work to Module that have 191 Excerpt Length value
  4.  */
  5.  
  6. function custom_trim_by_character( $excerpt, $post_id, $length, $excerpt_more ) {
  7.     if ( 191 !== $length ) {
  8.         return $excerpt;
  9.     }
  10.     $post         = get_post( $post_id );
  11.     $post_excerpt = $post->post_excerpt;
  12.  
  13.     if ( empty( $post_excerpt ) ) {
  14.         $post_excerpt = $post->post_content;
  15.     }
  16.  
  17.     $post_excerpt = preg_replace( '/\[[^\]]+\]/', '', $post_excerpt );
  18.     $post_excerpt = wp_trim_words( $post_excerpt, 9999, '' );
  19.     $post_excerpt = substr( $post_excerpt, 0, 50 ) . ' ...';
  20.  
  21.     return $post_excerpt;
  22. }
  23. add_filter( 'jnews_module_excerpt', 'custom_trim_by_character', 10, 4 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement