Skip to content

Instantly share code, notes, and snippets.

@hashihei
Created December 28, 2019 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashihei/f8337a0b6644e0031df5a73e62a84e07 to your computer and use it in GitHub Desktop.
Save hashihei/f8337a0b6644e0031df5a73e62a84e07 to your computer and use it in GitHub Desktop.
WordPress_tag_reference
/*記事に紐づけられたタグ配列情報を取得*/
$tags = get_the_tags();
/*タグ情報が空かどうかを確認*/
if ( !empty( $tags ) ) {
/*タグ情報が設定されている場合は、1つ目のタグ情報を読み取り、
fontawsomeのタグを構成し、出力する */
echo '<div><i class="' . $tags[0]->description . '"></i><div>' . $tags[0]->name . '</div></div>';
}else{
/*タグ情報の設定がない場合は、fa-laptop-code の絵文字を出力*/
echo '<div><i class="fas fa-laptop-code"></i><div>' . $tags[0]->name . '</div></div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment