i am not 100% sure on this but you could try this:
// utility function to check if text is Japanese
function is_japanese_excerpt($excerpt) {
$pattern = "/[\p{Han}\p{Katakana}\p{Hiragana}]+/u";
$matches = array();
preg_match_all($pattern, $excerpt, $matches);
if (count($matches[0]) > 0) {
return true; // excerpt contains Japanese characters
} else {
return false; // excerpt does not contain Japanese characters
}
}
// filter the excerpt length
function custom_excerpt_length($length) {
$excerpt = get_the_excerpt();
if (is_japanese_excerpt($excerpt)) {
return 20; // set Japanese excerpt length to 20 characters
}
return $length;
}
add_filter('excerpt_length', 'custom_excerpt_length');
Thanks for this. Unfortunately, when I put this in functions.php, the website does not display (just keep on trying to load the page). I deleted the code and reload the page again, it shows with no issue.