add_filter( 'term_links-post_tag', 'paulc_add_custom_class' ); function paulc_add_custom_class( $links ) { $new_links = array(); foreach ( $links as $link ) { preg_match( "|<a.*[^>]*>([^<]*)|i", $link, $matches ); $class = strtolower( $matches[1] ); $link = str_replace( 'rel="tag"', 'class="' . str_replace( " ", "-", $class ) . '" rel="tag"', $link ); $new_links[] = $link; } return $new_links; }
Chỉ cần thêm đoạn mã trên vào tệp functions.php của chủ đề đang hoạt động của bạn. Nó sẽ thêm slug thẻ vào tham số lớp của thẻ anchor.