Function for Post Format icons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Output Post Format icons | |
* | |
* Outputs an icon for each post format. Set up to use Fontawesome, | |
* but can be used with anything, or you can just use CSS. | |
* | |
* @return string | |
*/ | |
function post_format_icon() { | |
global $post; | |
// get current post ID | |
$id = $post->ID; | |
// get post format | |
$format = get_post_format( $id ); | |
// array of icons as $format => $icon key/value pairs | |
$icons = [ | |
'standard' => 'fa-pencil', | |
'aside' => 'fa-sticky-note', | |
'chat' => 'fa-comments', | |
'gallery' => 'fa-picture-o', | |
'link' => 'fa-external-link', | |
'image' => 'fa-camera', | |
'quote' => 'fa-quote-left', | |
'status' => 'fa-commenting', | |
'video' => 'fa-video-camera' | |
]; | |
// format will return false if no format is set. So, evaluate against this.. | |
// if format = false then $icon = standard, else icon = selected format | |
$format == ( false ) ? $icon = $icons['standard'] : $icon = $icons[ $format ]; | |
// html to be output | |
$output = '<span class="fa-stack"><i class="fa fa-circle fa-stack-2x"></i><i class="fa fa-stack-1x fa-inverse ' . $icon . '"></i></span>'; | |
// return the output | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It’s not working