WordPress: aggiungere una classe CSS ai post in base al formato

Come aggiungere una classe CSS ai post di WordPress in base al loro formato.

WordPress di Gabriele Romanato

In base al formato dei nostri post di WordPress possiamo aggiungere delle classi CSS speciali usando l'hook post_class.

Aggiungete il seguente codice al file functions.php, modificando ovviamente il formato del post e la classe CSS:


function add_class_to_post_format($classes) {
	global $post;
	$id = $post->ID;

	if(has_post_format('status', $id)) {
		$classes[] = 'format-status';
	}

	return $classes;
}

add_filter('post_class', 'add_class_to_post_format');

Commenti