Home » Web Design and Development » Content Management System » Wordpress » How to add category cloud in single post / page in WordPress

How to add category cloud in single post / page in WordPress

Category cloud can be added by using the taxonomy argument to cause a cloud of categories to display. You can either modify wp-content/yourtheme/single.php from ssh or using ftp OR you can login to wordpress dashboard, and go to “Appearance -> Editor -> ad click “single.php”

Post below line,

<?php wp_tag_cloud( array( 'taxonomy' => 'category' ) ); ?>

After,

<div class="thecontent">
    <?php the_content(); ?>
</div>

So, the final change could look like as below,

<div class="thecontent">
    <?php the_content(); ?>
</div>
<?php wp_tag_cloud( array( 'taxonomy' => 'category' ) ); ?>

To update into single page, modify the page.php as above.

If we want to customise the look of default Category cloud, we can modify the following code from wp-includes/category-template.php to add a border , and fill the color with boxed looks as below,

  // Generate the output links array.
foreach ( $tags_data as $key => $tag_data ) {
        $class = $tag_data['class'] . ' tag-link-position-' . ( $key + 1 );
        $a[]   = sprintf(
                '<a href="%1$s"%2$s class="%3$s" style="font-size: %4$s; color: #fff; border: 1px solid; margin: 1px 1px; display: inline-block; padding: 5px 5px; background-color: #777;"%5$s>%6$s%7$s</a>',
        );

Reference – https://developer.wordpress.org/reference/functions/wp_tag_cloud/


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment