Skip to content

Instantly share code, notes, and snippets.

@smutek
Created March 9, 2016 03:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save smutek/f15e7723db1e5e84c23b to your computer and use it in GitHub Desktop.
Save smutek/f15e7723db1e5e84c23b to your computer and use it in GitHub Desktop.
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
Copy link

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