InfoHeap
Tech tutorials, tips, tools and more
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Wordpress customization tutorials

  • Handle pagination in wordpress custom php code
  • How to and why disable wordpress cron
  • How to customize wordpress image alt tag
  • How to display date in wordpress pages
  • How to display wordpress page list with specific custom field value
  • How to display wordpress top level pages
  • How to hide a post from home and RSS feed in wordpress
  • How to include bootstrap javascript and css in wordpress post
  • How to include wordpress pages in archives
  • How to override priority and change frequency in Yoast xml sitemap
  • How to remove xmlrpc from wordpress headers
  • How to setup wordpress custom query params with pretty url format
  • How to show wordpress pages on front page with skip_home custom field
  • How to use google custom search for wordpress site
  • How to write custom php in wordpress
  • No frills social share links for Wordpress sites
  • Using Wordpress custom field for displaying code
  • Wordpress - add content filter after shortcode execution
  • Wordpress - customize category and tag links
  • Wordpress - customize facebook plugin opengraph meta tags
  • Wordpress - customize posts per page for tag, category and date archive pages
  • Wordpress - exclude specific posts from archive pages
  • Wordpress - get posts/pages with missing meta key
  • Wordpress - how to add filter to description meta tag
  • Wordpress - how to create custom tag cloud
  • Wordpress - how to exclude specific tag posts from a tag archive page
  • Wordpress - write custom php log to separate file
  • Wordpress how to check if a post is being viewed by admin
 
  • Home
  • > Tutorials
  • > Wordpress
  • > Wordpress customization

WordPress – how to create custom tag cloud

By admin on Dec 9, 2015

WordPress has support for displaying tag cloud using wp_tag_cloud. It displays tag cloud and has support for including and excluding tags and specifying mininum and maximum number of posts.

At times we may need extra customisation (e.g. anchor title attribute, etc) in tag cloud. Here is the wordpress php code snippet you can use to have your own custom tag cloud:

<?php
function my_tags() {
  $tags_include = array('slug1', 'slug2');
  $tags_exclude = array('slug3');
  $tag_count_threshold = 8;
  $tags = get_tags();
  $html = "<div>";
  $sep = "";
  foreach ( $tags as $tag ) {
    $tag_link = get_tag_link( $tag->term_id );
    $name = $tag->name;
    $desc = $tag->description;
    $count = $tag->count;
    if (!in_array($tag->slug, $tags_include)) {
      if ($count < $tag_count_threshold || in_array($tag->term_id, $tags_exclude)) {
        continue;
      }
    }
    $title = ($desc)? $desc : $name;
    $atext = ($desc)? $desc : $name;
    $html .= $sep;
    $sep = " | ";
    $html .= "<a href='{$tag_link}' title='$title' class='{$tag->slug}'>$atext</a>";
  }
  $html .= "</div>\n";
  return $html;
}

echo my_tags();
?>

Approach taken in wordpress custom tag cloud code

  1. Retrieve all tags from db.
  2. If a tag slug is in include list it must be displayed.
  3. If a tag slug is in exclude list or has count < threshold value, hide it.
  4. Display all other tags.

Suggested posts:

  1. How to display wordpress page list with specific custom field value
  2. Using WordPress custom field for displaying code
  3. How to setup wordpress custom query params with pretty url format
  4. How to display date in wordpress pages
  5. WordPress – query to dump all tags
  6. How to write custom php in wordpress
  7. Handle pagination in wordpress custom php code
  8. WordPress – write custom php log to separate file
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Tutorials, Wordpress, Wordpress customization

Follow InfoHeap

facebook
twitter
googleplus
  • Browse site
  • Article Topics
  • Article archives
  • Recent Articles
  • Contact Us
  • Omoney
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries

Copyright © 2023 InfoHeap.

Powered by WordPress