Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Function for Post Format icons
<?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;
}
@web2go

This comment has been minimized.

Copy link

@web2go web2go commented Mar 21, 2020

It’s not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.