Title: Making a shortcode?
Last modified: August 21, 2016

---

# Making a shortcode?

 *  [j4ze](https://wordpress.org/support/users/j4ze/)
 * (@j4ze)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/making-a-shortcode/)
 * Im having a trouble creating a short code, that gives me the ability to show 
   a list of all my categories along with the number of posts in them.
 * Ex:
    Travelling (2) Fashion (3) Food (0)
 * The listed categories should also work as links to the posts regarding that category.
   
   As i understand after a lot of google’ing, what i need is a shortcode that does
   the same as the wp_list_categories function
 *     ```
       <ul>
       <?php wp_list_categories('orderby=name&show_count=1'); ?>
       </ul>
       ```
   
 * The reason why i need it to be a shortcode, is that i have to use it in a text
   widget – unfortunately the category-widget is not suitable for my purpose.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/making-a-shortcode/#post-4199679)
 * This should get you started:
 *     ```
       // Shortcode to return wp_list_categories()
       // Usage: [mam_list_categories]
       function mam_list_categories_func() {
          $cat_list =  wp_list_categories('orderby=name&show_count=1&echo=0');
          return "<ul>$cat_list</ul>";
       }
       add_shortcode('mam_list_categories','mam_list_categories_func');
       ```
   
 *  Thread Starter [j4ze](https://wordpress.org/support/users/j4ze/)
 * (@j4ze)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/making-a-shortcode/#post-4199687)
 * Thank you so much for your help, I’ve figured out some code that works for me,
   but however I’m still not fully satisfied.
    This is my code:
 *     ```
       function list_categories_func($atts){
   
       $cat_list = wp_list_categories('orderby=name&show_count=1&echo=0');
   
       return $cat_list . '</ul>';
       }
       add_shortcode('list-categories', 'list_categories_func');
       ```
   
 * And it returns this list:
    – Categories – Category 1 (x posts)
 * You can see it on my site, left widget menu: [http://thatgirlcanez.com](http://thatgirlcanez.com)[**
   NSFW**]
 * I want to remove the category-title “Categories” since i already have a button
   showing that. And then i want all of my categories to show – even if they don’t
   have posts, so it would look like this:
    -Category 1 (2) -Category 2 (1) -Category
   3 (0) and so on.
 *  [ubikus](https://wordpress.org/support/users/ubikus/)
 * (@ubikus)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/making-a-shortcode/#post-4199690)
 * Add this:
    ‘orderby=name&show_count=1&echo=0**&title_li=&hide_empty=0**‘

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Making a shortcode?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [ubikus](https://wordpress.org/support/users/ubikus/)
 * Last activity: [12 years, 6 months ago](https://wordpress.org/support/topic/making-a-shortcode/#post-4199690)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
