Skip to content

Snippet: Alter The Post Format Icons

The Post with Icons widget and other theme functions may display an icon based on the current post format. You can easily filter the format icon classname using a filter like in the example above. You can refer to the Theme Icons list for the correct classname or use your own classname to target via CSS or a 3rd party icon set.

/**
 * Alter The Post Format Icons.
 *
 * @link https://total.wpexplorer.com/docs/snippets/post-format-icons/
 */
add_filter( 'wpex_post_format_icon', function() {
	$format = get_post_format() ?: 'post';

	switch ( $format ) {
		case 'video':
			$icon = 'ticon ticon-video-camera';
			break;
		case 'audio':
			$icon = 'ticon ticon-music';
			break;
		case 'gallery':
			$icon = 'ticon ticon-file-photo-o';
			break;
		case 'quote':
			$icon = 'ticon ticon-quote-left';
			break;
		default:
			$icon = 'ticon ticon-file-text-o';
			break;
	}

	return $icon;
} );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top