wordpress

タイトル、本文の文字制限

投稿日:

【タイトル】

if(mb_strlen($post->post_title, 'UTF-8')>18){
   $title= mb_substr($post->post_title, 0, 18, 'UTF-8');
   echo $title.'…';
}else{
   echo $post->post_title;
}

【本文】

if(mb_strlen($post->post_content, 'UTF-8')>200){
   $content= mb_substr(strip_tags($post->post_content), 0, 200, 'UTF-8');
   echo $content.'…';
}else{
   echo strip_tags($post->post_content);
}

※本文の場合はhtmlを無効にするのを忘れずに

-wordpress

関連記事

no image

WordPressでPHP8エラーが出るとき

Deprecated: PHP Startup: Use of mbstring.internal_encoding is deprecated in Unknown on line 0   …

no image

Smart Custom Fields(SCF)

https://b-risk.jp/blog/2020/10/smart-custom-fields/    

no image

【Contact Form 7 】ドロップダウン1行目に「選択してください」を入れる

ドロップダウン(select)の初期状態を、「選択してください」などのラベルとともに、未選択状態にするには、first_as_labelを記述する。 [select your-country firs …

no image

WordPressでgoogleフォント読み込み functions

wp_enqueue_style( ‘googlefonts’, “https://fonts.googleapis.com/css2?family=Meie+Sc …

no image

ショートコードの呼び出し

テンプレートで直接ショートコードを呼び出す記述。 <?php echo do_shortcode(‘[ショートコードの文字列]’); ?>