File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ' );
You can’t perform that action at this time.
0 commit comments