2012-03-08 12 views
0

を私は機能と、彼らは25charactersより長い場合は、タイトルを短縮し、トリプルドットを追加するフィルタを持っている現時点では「...」基準が満たされた場合、関数を実行する - ワードプレス

しかし、それはドットを追加すべてのタイトルにタイトルが25文字より長い場合にのみ、次のコードを実行するにはどうすればよいですか?

function japanworm_shorten_title($title) { 
    $newTitle = substr($title, 0, 25); // Only take the first 25 characters 

    return $newTitle . " …"; // Append the elipsis to the text (...) 
} 
add_filter('the_title', 'japanworm_shorten_title', 10, 1); 

答えて

2

あなたは、PHPのstrlenを使用することができます:http://php.net/manual/en/function.strlen.php

あなたのコードは次のように行くだろう:

完璧なthatsの
function japanworm_shorten_title($title) { 
if (strlen($title) > 25){ 
$title = substr($title, 0, 25).'…'; 
} 
return $title; 
} 

add_filter('the_title', 'japanworm_shorten_title', 10, 1); 
+0

!どうもありがとうございました! – Miro

関連する問題