Skip to content

Modify Post Format Icons

The Post with Icons widget and other theme features may display an icon based on the current post format. You can easily filter the format icon’s class name using a filter, as shown in the example above. For the correct class name, check the Theme Icons list, or use your own class name to target it via CSS or a third-party icon set.

You can also pass an SVG as the icon name if you want to use a third-party SVG icon instead of a class-based icon. This allows for greater flexibility and keeps your icons fully customizable.

/**
 * Alter The Post Format Icons.
 *
 * @link https://totalwptheme.com/docs/snippets/post-format-icons/
 */
add_filter( 'totaltheme/post/format/icon_name', function() {
	$format = get_post_format() ?: 'post';
	switch ( $format ) {
		case 'video':
			// you can pass a theme icon name or a custom SVG for the icon
			$icon = 'video-camera';
			break;
		case 'audio':
			$icon = 'music';
			break;
		case 'gallery':
			$icon = 'file-photo-o';
			break;
		case 'quote':
			$icon = 'quote-left';
			break;
		default:
			$icon = '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)
Related Snippets
Back To Top