1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

wordpress 一覧ページでタイトルなどの文字数を制限する

Last updated at Posted at 2015-06-03

いわゆる「あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめも…」のように、
文字数を超えた部分を、…と表示する方法。タイトルと本文2つ用意してみた。
文字数以下ならば、…と表示されないようにしている。

タイトル

<?php if(mb_strlen($post->post_title)>20) { $title= mb_substr($post->post_title,0,20) ; echo $title. ・・・ ;
} else {echo $post->post_title;}?>

本文

function.php

/*excerpt*/
function change_excerpt_mblength($length) {
return 150;
}
add_filter('excerpt_mblength', 'change_excerpt_mblength');

function new_excerpt_more($more) {
	return '…';
}	
add_filter('excerpt_more', 'new_excerpt_more');
表示させるphp

<?php the_excerpt(); ?>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?