Advertisement
Guest User

wp excerpt chinese fix

a guest
Aug 27th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. function dez_get_custom_the_excerpt($limit='',$more='') {
  2. global $post;
  3. $thepostlink = '<a class="readmore" href="'. get_permalink() . '" title="' . the_title_attribute('echo=0') . '">';
  4. $custom_text = get_post_field('post_excerpt',$post->ID);
  5. $content = get_the_content();
  6.  
  7. //if use manual excerpt
  8. if($custom_text) {
  9. if($more) {
  10.     $excerpt = $custom_text . $thepostlink . $more . '</a>';
  11.     } else {
  12.     $excerpt = $custom_text;
  13.     }
  14.  
  15. } else {
  16.  
  17. //check if its chinese character input
  18. $chinese_output = preg_match_all("/\p{Han}+/u", $post->post_content, $matches);
  19. if($chinese_output) {
  20.  
  21. if($more) {
  22. $excerpt = mb_substr( get_the_excerpt(), 0, $limit*2 ) . '...' . $thepostlink . $more.'</a>';
  23. } else {
  24. $excerpt = mb_substr( get_the_excerpt(), 0, $limit*2 ) . '...';
  25. }
  26.  
  27. } else {
  28.  
  29. //remove caption tag
  30. $content_filter_cap = strip_shortcodes( $content );
  31. //remove email tag
  32. $pattern = "/[^@\s]*@[^@\s]*\.[^@\s]*/";
  33. $replacement = "";
  34. $content_filter = preg_replace($pattern, $replacement, $content_filter_cap);
  35.  
  36. if($more) {
  37.     $excerpt = wp_trim_words($content_filter, $limit) . $thepostlink.$more.'</a>';
  38.     } else {
  39.     $excerpt = wp_trim_words($content_filter, $limit);
  40.     }
  41. }
  42. }
  43. return apply_filters('meso_get_custom_excerpt',$excerpt);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement