From 679afafaab83ee2545d8e83f8fa94599ad9bc756 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Fri, 15 Nov 2019 10:48:52 +0100 Subject: [PATCH] fix #76 --- sempress/inc/semantics.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/sempress/inc/semantics.php b/sempress/inc/semantics.php index 5f9b2bb..cf2aff1 100644 --- a/sempress/inc/semantics.php +++ b/sempress/inc/semantics.php @@ -251,3 +251,38 @@ function sempress_semantics( $id ) { echo ' ' . esc_attr( $key ) . '="' . esc_attr( join( ' ', $value ) ) . '"'; } } + +/** + * Add `p-category` to tags links + * + * @link https://www.webrocker.de/2016/05/13/add-class-attribute-to-wordpress-the_tags-markup/ + * + * @param array $links + * @return array + */ +function sempress_term_links_tag( $links ) { + $post = get_post(); + $terms = get_the_terms( $post->ID, 'post_tag' ); + + if ( is_wp_error( $terms ) ) { + return $terms; + } + + if ( empty( $terms ) ) { + return false; + } + + $links = array(); + foreach ( $terms as $term ) { + $link = get_term_link( $term ); + + if ( is_wp_error( $link ) ) { + return $link; + } + + $links[] = ''; + } + + return $links; +} +add_filter( 'term_links-post_tag', 'sempress_term_links_tag' );