blue

get_the_author()のカスタマイズ(半角スペースをトル)

  • Posted by: SOMA Hitoshi
  • December 27, 2016 3:45 PM
  • wordpress

 WordPressの小ネタはつづく。

 WordPressの著者(ユーザー)の表示名というと、

たとえばこんなふうに設定するわけだが、この標準機能に乗っかるかぎりはどうしても「姓」と「名」のあいだに半角スペースが空いてしまう。

 get_the_author()で取得されるこの表示名において、姓と名のあいだの半角スペースを取りたい、というたいへんこまかなことを考えた場合に、get_the_author()の処理にどのようにフックをかけたらいいかという話。

function get_the_author_display_name_filter( $name ) {
	$name = str_replace(' ','',$name);
	return $name;
}
add_filter('get_the_author_display_name', 'get_the_author_display_name_filter');

 こちらを functions.phpに追記することでいけた。

関連記事

トラックバック(0)

トラックバックURL: https://web-conte.com/blue/mt-tb.cgi/1089