• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

nSiteful Web Builders

Building a Better Web - One Site at a Time.

  • Home
  • About
    • Testimonials
    • Resources
  • Web Sites
  • Online Marketing
  • WordPress Support
    • Customized WordPress Training
    • 60-for-60 Sessions
  • Web Applications
  • Blog
    • Archive Listing Minimalistic
    • Blog Articles Grouped by Category
    • Case Studies
    • General
    • Portfolio
    • Reviews
    • Snippets
    • Techniques
  • Contact Jeff
    • Purchase Retainer Consulting Hours
    • About Retainer Consulting Hours
Screenshot

By Jeff Cohan, May 13, 2016

Display WordPress and WooCommerce Tags as Lists

Last updated August 5th, 2022 at 11:10 am

WordPress tag widgets display tags in a tag cloud by default. Here’s how to override that default behavior; specifically, how to display WordPress and WooCommerce tags as lists.

For the Standard WordPress Tag Cloud Widget

tag-cloud-problem
Since WordPress 4.4, the functioning of the widget_tag_cloud_args filter hook (see here) changed in a way that I cannot adequately explain. However, what I do know is that the addition of the 'echo' => false argument somehow (counterintuitively, if you ask me) removed all the structural wrappers of the tag cloud unless one explicitly set the value of the 'echo' argument to false.

The short answer is that without passing 'echo' => false to the filter, the result is (in WordPress 4.4+) that your tag cloud (or list) will hug the left margin of the sidebar (and any title you enter in the widget will not appear). This is because the tag listing is being echoed, rather than returned for processing. Again, I wish I understood why. If you can explain this, please comment below.

The code snippet should be added to your theme’s (or child theme’s) functions.php or in a plugin. I tend to put these in a file in the mu-plugins folder.

Version One:

This version works. Note the added 'echo' => false line.

add_filter('widget_tag_cloud_args','nwb_tag_cloud_filter');
function nwb_tag_cloud_filter($args) {
	$args = array(
		'smallest' => 14, 
		'largest' => 14, 
		'format' => 'list', 
		'unit' => 'px', 
		'echo' => false, 
		);
	return $args;
}

Version Two:

This version, offered by afainu in the WordPress support forums, also works and may be preferable. That’s because it uses WordPress’ enhanced version of array_merge(), thus maintaining, rather than overwriting, the defaults.

add_filter('widget_tag_cloud_args','nwb_tag_cloud_filter');
function nwb_tag_cloud_filter($args) {
	$my_args = array(
		'smallest' => 14, 
		'largest' => 14, 
		'format' => 'list', 
		'unit' => 'px', 
		);
	$args = wp_parse_args( $args, $my_args );
	return $args;
}

For the WooCommerce Product Tags Widget

To convert the WooCommerce Product Tags Widget display from tag cloud to list, use something like this. The key here is the taxonomy argument, whose value must correspond to the slug for the WooCommerce product tag (‘product_tag’, by default).

add_filter('woocommerce_product_tag_cloud_widget_args', 'nwb_woo_tag_cloud_filter');
function nwb_woo_tag_cloud_filter($args) {
	$args = array(
		'smallest' => 14, 
		'largest' => 14, 
		'format' => 'list', 
		'taxonomy' => 'product_tag', 
		'unit' => 'px', 
		);
	return $args;
}

Related Posts

  1. Diagnostic PHP: Get All Included Files
  2. How to add an About Us blurb to every WordPress blog post
  3. Dynamic Linear Gradients for Background Images in Genesis
  4. WordPress Categories and Tags
  5. Which Categories and Tags Should I Use?
  • Choose the best match.

Written by Jeff Cohan · Categorized: Snippets · Tagged: php, Taxonomies, WooCommerce, WordPress

  • Choose the best match.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

mailchimp signup

Subscribe to get notified when new articles are published. Unsubscribe any time. No spam. I promise. Check out my newsletter archives.

social

Twitter Facebook LinkedIn

Recent Articles

  • Use Case for Custom Post Type: “In The News” March 10, 2023
  • Create a Custom Shortcode to Display a MemberPress Membership Price ANYWHERE on Your Website February 5, 2023
  • Avoid Direct Styling; Use CSS Instead September 21, 2022
  • Blog Tags: What They Are (and What They’re Not) August 5, 2022
  • How to Create a Simple Custom Events Plugin May 24, 2022

Filter By Category/Tag

Categories

  • Case Studies (7)
  • General (61)
  • Portfolio (5)
  • Reviews (12)
  • Snippets (16)
  • Techniques (38)

Popular Tags

Advanced Custom Fields Blogging Child Themes Content Marketing CSS CSS Grid Customer Service Custom Fields Custom Post Types Diagnostics Facebook FooGallery Genesis Gutenberg HTML Images iPhone Libra Live Chat Marketing Media MemberPress MemberPress Courses mu-plugins MySQL Photo Gallery php Pinterest Plugins Post Formats Pricing Project Management Security SEO Seth Godin Shortcodes Social Networking Surveys Taxonomies Trello Twitter Video Web design Web forms WordPress

siteground wp hosting

Web Hosting

wp101

EasyWordPresstutorialvideosforbeginners.
MemberPress CTA

Footer

Background

Web Sites | WordPress Support | Web Applications.

Formally trained in liberal arts and education (I have a B.A. in Government from Harvard and studied Secondary Education at Rutgers Graduate School), I have honed my skills in the communication arts and sciences as a teacher, trainer, instructional designer, writer, photographer, calligrapher, helpdesk manager, database programmer, and multimedia developer.

(I've also been a group counselor, waiter, bartender, bicycle messenger boy, computer salesman, carpenter's helper, financial analyst, and school board president.)

Tech

Systems since 1983.
Web sites since 1994.
PHP since 2001.
WordPress since 2007.

Contact

770-772-5134
Email Jeff
Send Money
All Ways

Copyright 2023, nSiteful Web Builders, Inc.

 

Subscribe

Pardon the interruption. I know popups can be annoying. But I’d love to have you as a subscriber.

Sign up to be notified when new articles are published. Unsubscribe any time.

* indicates required

Powered by MailChimp

×