Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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