Skip to content

Commit 679afaf

Browse files
committed
fix #76
1 parent fbcb523 commit 679afaf

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

sempress/inc/semantics.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,38 @@ function sempress_semantics( $id ) {
251251
echo ' ' . esc_attr( $key ) . '="' . esc_attr( join( ' ', $value ) ) . '"';
252252
}
253253
}
254+
255+
/**
256+
* Add `p-category` to tags links
257+
*
258+
* @link https://www.webrocker.de/2016/05/13/add-class-attribute-to-wordpress-the_tags-markup/
259+
*
260+
* @param array $links
261+
* @return array
262+
*/
263+
function sempress_term_links_tag( $links ) {
264+
$post = get_post();
265+
$terms = get_the_terms( $post->ID, 'post_tag' );
266+
267+
if ( is_wp_error( $terms ) ) {
268+
return $terms;
269+
}
270+
271+
if ( empty( $terms ) ) {
272+
return false;
273+
}
274+
275+
$links = array();
276+
foreach ( $terms as $term ) {
277+
$link = get_term_link( $term );
278+
279+
if ( is_wp_error( $link ) ) {
280+
return $link;
281+
}
282+
283+
$links[] = '<a class="p-category" href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
284+
}
285+
286+
return $links;
287+
}
288+
add_filter( 'term_links-post_tag', 'sempress_term_links_tag' );

0 commit comments

Comments
 (0)