View difference between Paste ID: JygebdLQ and QveC9Zh2
SHOW: | | - or go back to the newest paste.
1
<?php 
2
add_filter( 'post_class', 'wpq_filter_post_class' );
3
4
function wpq_filter_post_class( $classes ) {
5
	
6
	if( is_singular() ) {
7
		
8
		global $post;
9
		
10
		$taxonomies = get_taxonomies( array( 'public' => true ) , 'names', 'and' );
11
12
		if ( is_array($taxonomies) ) {
13
			foreach ( $taxonomies as $taxonomy ) {
14
				if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) {
15
					foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) { 
16-
						if ( empty($term->slug ) ) 
16+
						if ( empty($term->slug ) || 'post_tag' == $taxonomy || 'category' == $taxonomy ) {
17-
						continue; 
17+
							continue; 
18-
						if ( 'post_tag' == $taxonomy ) 
18+
						} else {
19-
						$classes[] = 'tag-' . sanitize_html_class( $term->slug, $term->term_id ); 
19+
							$classes[] = sanitize_html_class( $term->slug, $term->term_id ); 
20-
						else 
20+
						}
21-
						$classes[] = sanitize_html_class( $taxonomy->name, $taxonomy ) . '-' . sanitize_html_class( $term->slug, $term->term_id ); 
21+
22
				}
23
			}
24
		}
25
	}
26
	
27
	return $classes;
28
	
29
}