Title: Shotcode Rand Categories &amp; Remove Title
Last modified: October 27, 2022

---

# Shotcode Rand Categories & Remove Title

 *  Resolved [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/)
 * Hey
 * I Can’t figure out the following:
 * 1) Using product_categories i want them to display in random order. Short code
   I use:
 * `[product_categories limit="3" columns="3" parent="689" orderby="rand" title="
   hide"]`
 * 2) I am displaying “Brands” with image logo that always feature the company name,
   hence, I don’t need a title for the category. In fact I don’t want the title 
   shown. How can I do that? As seen above title=”hide” or “none” will not do the
   trick.
 * Thx in advance 🙂
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fshotcode-rand-categories-remove-title%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/page/2/?output_format=md)

 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16146273)
 * I found this code: [random_product_categories](https://gist.github.com/filipecsweb/32467a20f2eeb39b0cbf)
 * and I need a bit of help. random_product_categories does not respect the limit
   value. I need it set as a variable in my SC and not just hardcoded in the Snippet.
   Who has this capacity?
 *     ```
       /**
        * Create new WooCommerce shortcode [random_product_categories]
        * based on [product_categories] (/wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php)
        * to output product categories randomically.
        *
        * This new shortcode uses all attributes used by [product_categories], except 'orderby' and 'order', of course.
        * See more in //docs.woothemes.com/document/woocommerce-shortcodes/ > Product Categories Section.
        */
       function random_product_categories_shortcode($atts){
       	global $woocommerce_loop;
   
       	$atts = shortcode_atts( array(
       		'number'     => null,
       		'columns'    => '4',
       		'hide_empty' => 1,
       		'parent'     => '',
       		'ids'        => ''
       	), $atts);
   
       	if(isset($atts['ids'])){
       		$ids = explode(',', $atts['ids']);
       		$ids = array_map('trim', $ids);
       	} 
       	else{
       		$ids = array();
       	}
   
       	$hide_empty = ($atts['hide_empty'] == true || $atts['hide_empty'] == 1) ? 1 : 0;
   
       	// get terms and workaround WP bug with parents/pad counts
       	$args = array(
       		'hide_empty' => $hide_empty,
       		'include'    => $ids,
       		'pad_counts' => true,
       		'child_of'   => $atts['parent']
       	);
   
       	$product_categories = get_terms('product_cat', $args);
   
       	/**
       	 * PHP shuffle function will shuffle the array of objects $product_categories
       	 */
       	shuffle($product_categories);
   
       	if ('' !== $atts['parent']){
       		$product_categories = wp_list_filter($product_categories, array('parent' => $atts['parent']));
       	}
   
       	if ($hide_empty){
       		foreach($product_categories as $key => $category){
       			if ($category->count == 0){
       				unset($product_categories[$key]);
       			}
       		}
       	}
   
       	if($atts['number']){
       		$product_categories = array_slice($product_categories, 0, $atts['number']);
       	}
   
       	$columns = absint($atts['columns']);
       	$woocommerce_loop['columns'] = $columns;
   
       	ob_start();
   
       	// Reset loop/columns globals when starting a new loop
       	$woocommerce_loop['loop'] = $woocommerce_loop['column'] = '';
   
       	if($product_categories){
   
       		woocommerce_product_loop_start();
   
       		foreach($product_categories as $category){
       			wc_get_template('content-product_cat.php', 
       				array(
       					'category' => $category
       				)
       			);
       		}
   
       		woocommerce_product_loop_end();
   
       	}
   
       	woocommerce_reset_loop();
   
       	return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
       }
       add_shortcode('random_product_categories', 'random_product_categories_shortcode');
       ```
   
 *  [Saif](https://wordpress.org/support/users/babylon1999/)
 * (@babylon1999)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16150291)
 * Hello [@hebhansen](https://wordpress.org/support/users/hebhansen/),
 * You don’t need to edit the original template for this, we can write a few CSS
   lines to take care of it.
 * Can you please attach a screenshot of that duplicate category name and highlight
   it if possible?
 * Also, please make sure to include the URL of the page itself.
 * Look forward to hearing back from you.
 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16150420)
 * Hey Saif
 * That sounds cool. Link to my site: _[ redundant link deleted ]_
 * Scrolling down a bit will take you to
 * > Brands
 * 3 logos display Alpha Industries, Brandit and HBH. As you can see all logos displayed
   will include the name of the brand, so the categories name = Brand Name should
   not display.
 * Note: when I activate the code above they display random, but all categories 
   are shown. In my case 8 brands, so I need to be able to set a limit. In my case
   3 or 4.
    -  This reply was modified 3 years, 7 months ago by [hebhansen](https://wordpress.org/support/users/hebhansen/).
    -  This reply was modified 3 years, 7 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16156237)
 * Update:
 * Attribute number=”x” limits the display to that number, hence, it replaces the
   limit attribute from products shortcode.
 * Attribute Columns work the same as for products.
 * I still have no solution to removing the category name for this display.
    -  This reply was modified 3 years, 7 months ago by [hebhansen](https://wordpress.org/support/users/hebhansen/).
 *  [Igor H](https://wordpress.org/support/users/ihereira/)
 * (@ihereira)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16156982)
 * Hi,
 * > I still have no solution to removing the category name for this display.
 * Does this CSS code work for you?
 *     ```
       .woocommerce ul.products li.product .woocommerce-loop-category__title, .woocommerce ul.products li.product .woocommerce-loop-product__title, .woocommerce ul.products li.product h3
       {
           visibility: hidden;
       }
       ```
   
 * 
    Link to image: [https://snipboard.io/7iRSDZ.jpg](https://snipboard.io/7iRSDZ.jpg)
 * To add the code, navigate to _WP Dashboard > Appearance > Customize > Additional
   CSS_.
 * I hope this helps.
    -  This reply was modified 3 years, 7 months ago by [Igor H](https://wordpress.org/support/users/ihereira/).
 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16157407)
 * Hey Igor
 * Code removes all titles, but also inside shop and that’s not going to work. Maybe
   if I add a class in shortcode for the front display. I will try that out….
 *  [anastas10s](https://wordpress.org/support/users/anastas10s/)
 * (@anastas10s)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16157689)
 * Hi there [@hebhansen](https://wordpress.org/support/users/hebhansen/) 👋
 * > Code removes all titles, but also inside shop and that’s not going to work.
   > Maybe if I add a class in shortcode for the front display. I will try that 
   > out….
 * Sounds good. Let us know how that goes!
 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16157807)
 * Not working, removes everything:
 *     ```
       .woocommerce ul.products li.product .woocommerce-loop-category__title,
       .woocommerce ul.products li.product .woocommerce-loop-product__title,
       .woocommerce ul.products li.product h3,
       .remove-title {
           visibility: hidden;
       }
       ```
   
 *  [Igor H](https://wordpress.org/support/users/ihereira/)
 * (@ihereira)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16157978)
 * Hi,
    Thanks for responding. It looks like I hit submit too fast, my apologies.
 *     ```
       .woocommerce-loop-category__title
       {
           visibility: hidden;
       }
       ```
   
 * Is this code working for you? Please let me know how that goes.
    -  This reply was modified 3 years, 7 months ago by [Igor H](https://wordpress.org/support/users/ihereira/).
 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16158202)
 * Hey Igor
 * It does not remove title from product, but it does remove ALL titles from ALL
   categories in woo.
 * I don’t want titles removed inside shop. Just on the frontpage. The display I
   call by shortcode in widget. The screendump you sent before.
 * Shortcode:
    `[random_product_categories class="remove-title" number="3" columns
   ="3" parent="689" title="hide"]`
 * Your css with my custom class does not work either:
 *     ```
       .woocommerce-loop-category__title .remove-title {
           visibility: hidden;
       }
       ```
   
    -  This reply was modified 3 years, 7 months ago by [hebhansen](https://wordpress.org/support/users/hebhansen/).
 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16158226)
 * Random function in post #2 works well on computer but not on mobile. Does anyone
   know why? Hint all random function on front does not work on mobile.
 * – Top Secret section
    – Brands Section – Testimonial Section
 * Can someone give me a lead to this….
 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16158233)
 * Someone pointed me here for a fix to remove category name on front. However, 
   I am not good with php, so I have no idea if it’s possible:
 *     ```
       <?php
       /**
        * The template for displaying product category thumbnails within loops.
        *
        * Override this template by copying it to yourtheme/woocommerce/content-product_cat.php
        *
        * @author 		WooThemes
        * @package 	WooCommerce/Templates
        * @version     2.4.0
        */
   
       if ( ! defined( 'ABSPATH' ) ) {
       	exit;
       }
   
       global $woocommerce_loop;
   
       // Store loop count we're currently on
       if ( empty( $woocommerce_loop['loop'] ) ) {
       	$woocommerce_loop['loop'] = 0;
       }
   
       // Store column count for displaying the grid
       if ( empty( $woocommerce_loop['columns'] ) ) {
       	$woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 );
       }
   
       // Increase loop count
       $woocommerce_loop['loop'] ++;
   
       ?>
   
       <li <?php wc_product_cat_class(); ?>>
       	<?php do_action( 'woocommerce_before_subcategory', $category ); ?>
   
       	<a href="<?php echo get_term_link( $category->slug, 'product_cat' ); ?>">
   
       		<?php
       			/**
       			 * woocommerce_before_subcategory_title hook
       			 *
       			 * @hooked woocommerce_subcategory_thumbnail - 10
       			 */
       			do_action( 'woocommerce_before_subcategory_title', $category );
       		?>
   
       		<h3>
       			<?php
       				echo $category->name;
   
       				//if ( $category->count > 0 )
       				//	echo apply_filters( 'woocommerce_subcategory_count_html', ' <mark class="count">(' . $category->count . ')</mark>', $category );
       			?>
       		</h3>
   
       		<?php
       			/**
       			 * woocommerce_after_subcategory_title hook
       			 */
       			do_action( 'woocommerce_after_subcategory_title', $category );
       		?>
   
       	</a>
   
       	<?php 
       		echo $category->description;
       		//get subcategories
       		$args = array(
       	       'hierarchical' => 1,
       	       'show_option_none' => '',
       	       'hide_empty' => 0,
       	       'parent' => $category->term_id,
       	       'taxonomy' => 'product_cat'
       	    );
   
       		$subcategories = get_categories($args);
       		//echo subcategory links
       		if(!is_null($subcategories)){
       			echo '<ul class="subcategories">';
       			foreach($subcategories as $subcat){
       				echo '<li><a href="/product-category/' . $subcat->category_nicename . '/">' . $subcat->name . '</a>';
   
       				//get subcategories of the sub-category
       				$args = array(
       			       'hierarchical' => 1,
       			       'show_option_none' => '',
       			       'hide_empty' => 0,
       			       'parent' => $subcat->term_id,
       			       'taxonomy' => 'product_cat'
       			    );
   
       			    $subchildren = get_categories($args);
       			    if(!is_null($subchildren)){
       			    	echo '<ul class="subcat-children">' . "\n";
       			    	foreach($subchildren as $subchild){
       			    		echo '<li><a href="/product-category/' . $subchild->category_nicename . '/">' . $subchild->name . '</a>' ."</li>\n";
       			    	}
       			    	echo '</ul>';
       			    }
   
       				echo "</li>\n";
       			}
       			echo '</ul>';
       		}
   
       		do_action( 'woocommerce_after_subcategory', $category ); 
   
       	?>
       </li>
       ```
   
 *  [anastas10s](https://wordpress.org/support/users/anastas10s/)
 * (@anastas10s)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/page/2/#post-16160143)
 * Hi there [@hebhansen](https://wordpress.org/support/users/hebhansen/) 👋
 * > I don’t want titles removed inside shop. Just on the frontpage.
 * Thanks for clarifying things further. Know more about [hiding the page title on specific pages, using CSS, at the article directly linked here](https://www.wpbeginner.com/plugins/how-to-hide-post-and-page-titles-in-wordpress-single-pages/#hiding-selective-wordpress-titles-css).
 * That article will help you adjust [the code snippet my colleague shared here](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/#post-16157978),
   to your needs.
 * > Random function in post #2 works well on computer but not on mobile. Does anyone
   > know why?
 * From what I understand, [this is already being discussed on GitHub (direct link here)](https://gist.github.com/filipecsweb/32467a20f2eeb39b0cbf).
   Therefore, feel free to continue the related correspondence there.
 * > Someone pointed me here for a fix to remove category name on front. However,
   > I am not good with php, so I have no idea if it’s possible
 * Kindly keep in mind we are not developers and only offer support for existing
   functionality.
 * Please see our Support Policy: [http://www.woocommerce.com/support-policy/](http://www.woocommerce.com/support-policy/)
 * For assistance with customization or development with your site, we recommend
   that you seek help from:
 * * A local web developer
    * [Codeable.io](https://woocommerce.com/codeable/) *
   [WooExperts](https://woocommerce.com/experts/) * [Stackexchange](http://wordpress.stackexchange.com/help/on-topic)
 * If you are comfortable coding yourself and have questions, I would also recommend
   that you consider:
 * * [WooCommerce developer Portal](https://developer.woocommerce.com/)
    * [WooCommerce Slack Community](https://woocommerceslack.herokuapp.com/)*
   [Advanced WooCommerce Facebook group](https://www.facebook.com/groups/advanced.woocommerce)
 * I hope that helps you to figure it out.
 * Feel free to get back to us if you have further questions.
 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/page/2/#post-16168557)
 * Update:
 * Above code is written by Filipe. He updated it so that category title can be 
   hidden while enjoying the random shuffle. You can get it at github:
 * [Random Product Categories w. Remove Title](https://gist.github.com/filipecsweb/32467a20f2eeb39b0cbf#gistcomment-4355134)
 * Shortcodes for the php:
 * [random_product_categories]
    [random_product_categories column=3 numbers=3] –
   NOTE numbers replace “limit” attribute in the product shortcode. [random_product_categories
   hide_title=1] – Titles under categories will not show. Useful when images are
   self explanatory, such as brands logo.
 *  Thread Starter [hebhansen](https://wordpress.org/support/users/hebhansen/)
 * (@hebhansen)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/page/2/#post-16169226)
 * Update on the Random obstruction. Turning off: Plugin
 * > WP-Optimize – Cache, Clean, Compress
 *  solved this. It’s reported here:
 * [Random Obstruction Report](https://wordpress.org/support/topic/bug-obstruction-of-random-displays/)

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/page/2/?output_format=md)

The topic ‘Shotcode Rand Categories & Remove Title’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [product categories](https://wordpress.org/support/topic-tag/product-categories/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [title](https://wordpress.org/support/topic-tag/title/)

 * 27 replies
 * 5 participants
 * Last reply from: [xue28 (woo-hc)](https://wordpress.org/support/users/xue28/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/shotcode-rand-categories-remove-title/page/2/#post-16175806)
 * Status: resolved