Advertisement
arie_cristianD

change_excerpt

Aug 14th, 2023 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. /**
  2.  * Change Trim from Words to Character
  3.  * change '2' to many character you want to display in exceprt
  4.  */
  5.  
  6. function custom_trim_by_character( $excerpt, $post_id, $length, $excerpt_more ) {
  7.     $post         = get_post( $post_id );
  8.     $post_excerpt = $post->post_excerpt;
  9.  
  10.     if ( empty( $post_excerpt ) ) {
  11.         $post_excerpt = $post->post_content;
  12.     }
  13.  
  14.     $post_excerpt = preg_replace( '/\[[^\]]+\]/', '', $post_excerpt );
  15.     $post_excerpt = wp_trim_words( $post_excerpt, 9999, '' );
  16.     $post_excerpt = substr( $post_excerpt, 0, 2 ) . '...';
  17.  
  18.     return $post_excerpt;
  19. }
  20. add_filter( 'jnews_module_excerpt', 'custom_trim_by_character', 10, 4 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement