How would I go about adding icons over post thumbnails according to their post format. So for example if I have a post with a post format of audio the thumbnail would show everywhere(widgets, category pages, home page, etc) with an audio icon over it. Can't seem to be able to figure out how to implement this.

2 Answers 2


You can use get_post_format($post_id) to retrieve each post's format, then you can assign a class to each post based on it's format.

Once you have that, you only need to define said classes to, for example, show an icon overlay on the ::after pseudo-element of the posts.

To obtain consistency between widgets, category pages, etc. you can either apply the previous to each or use a unified post template for everything.


Code elaboration for answer provided by @Leuquim

$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
echo $input[$rand_keys[1]] . "\n";

//Check for current post type using get_post_type( $post )

//Check the current post type and assign classes accordingly

if($input[$rand_keys[1]] == "Neo")
  $class_assigned = "audio_post"
else if($input[$rand_keys[1]] == "Cypher")
  $class_assigned = "video_post"

//so on and so forth

And accordingly you can add the CSS rules for adding a post type specific icon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.