How to filter wp_tag_cloud’s title attribute for SEO
The WordPress tag cloud doesn’t have very friendly linking (no no follow links) so let’s make a quick function to filter the links and replace them with something more search engine friendly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
//@author: Devin Walker //filter the tag cloud function with SEO friendly title text function wp_title_tag_cloud_filter($return, $tags) { $pattern = '/(\d+) topics/'; echo "<ul class='wp-tag-cloud'>"; foreach ( $tags as $key => $tag ) { $tag_name = $tags[ $key ]->name; $tag_title = $tags[ $key ]->name. " coupons"; $tag_link = $tags[ $key ]->link; $term_id = $tags[ $key ]->id; echo "<li><a href='".$tag_link."' title='".$tag_title."' class='tag-link-".$term_id."'>".$tag_name."</a></li>"; } echo "</ul>"; } add_filter('wp_generate_tag_cloud', 'wp_title_tag_cloud_filter', 10, 2); |