Title: &#8220;Missing argument 2&#8221; on a custom function
Last modified: March 18, 2017

---

# “Missing argument 2” on a custom function

 *  Resolved [breathelifein](https://wordpress.org/support/users/biellebrunner/)
 * (@biellebrunner)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/missing-argument-2-on-a-custom-function/)
 * I’m using this function to add a class to the category links in the loop:
 *     ```
       add_filter('the_category','add_class_to_category',10,3);
       function add_class_to_category( $thelist, $separator, $parents){
           $class_to_add = 'cat';
           return str_replace('<a href="', '<a class="' . $class_to_add . '" href="', $thelist);
       }
       ```
   
 * But when I go to create a new (or edit) a post, I get this message on the categories
   box, above the categories list:
 * > Warning: Missing argument 2 for add_class_to_category() in …/public_html/wp-
   > content/themes/tema12/functions.php on line 186.
 * Line 186 is: `function add_class_to_category( $thelist, $separator, $parents){`
 * What argument am I missing?

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

 *  [csloisel](https://wordpress.org/support/users/csloisel/)
 * (@csloisel)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/missing-argument-2-on-a-custom-function/#post-8930464)
 * Glancing at core, that filter seems to be very unstandardized and all over the
   place on what is actually being filtered. It looks like some of the filters don’t
   even pass more than a single argument. Since you aren’t even using any of the
   other args, I would just remove the other two completely and only expect the 
   first one, or put in default values for the last two.
    -  This reply was modified 9 years, 2 months ago by [csloisel](https://wordpress.org/support/users/csloisel/).
 *  [csloisel](https://wordpress.org/support/users/csloisel/)
 * (@csloisel)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/missing-argument-2-on-a-custom-function/#post-8930466)
 * To clarify, I would change this:
 *     ```
       add_filter('the_category','add_class_to_category',10,3);
       function add_class_to_category( $thelist, $separator, $parents){
       ```
   
 * To this:
 *     ```
       add_filter('the_category','add_class_to_category',10);
       function add_class_to_category( $thelist ){
       ```
   
 * Or this:
 *     ```
       add_filter('the_category','add_class_to_category',10,3);
       function add_class_to_category( $thelist, $separator = '', $parents= '' ){
       ```
   
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/missing-argument-2-on-a-custom-function/#post-8932495)
 * Right, that solves the issue for your filter, but the filter’s application in
   core should be standardized. A Trac ticket should be filed so the issue is on
   record. I know the post edit screen errors are from the filter being applied 
   in wp_popular_terms_checklist(). Do you happen to have a list of other problematic
   locations? I know it wouldn’t be difficult to find the others, but if you happen
   to have one already, why bother? 🙂
 * If you have such a list, would you be willing to file a [Trac ticket](https://core.trac.wordpress.org/newticket)?
   Or I’d be willing to file it. I’d appreciate a list if you have, otherwise I’ll
   figure it out.
 * Thanks for whatever help you can provide, even if it’s just bringing it to our
   attention.
 *  Thread Starter [breathelifein](https://wordpress.org/support/users/biellebrunner/)
 * (@biellebrunner)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/missing-argument-2-on-a-custom-function/#post-8963513)
 * csloisel, thank you! That solved my problem.
 * bcworkz, sorry, but you lost me. Haha You wanted to know where else that error
   message was showing up? Basically, anywhere where I could chose the categories,
   like quick edit on the posts list. Feel free to file a Trac ticket if you think
   it’ll help WP solve this issue.
    Thank you!
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/missing-argument-2-on-a-custom-function/#post-8966775)
 * Heh, I must be blind. I somehow thought you were answering your own question 
   instead of csloisel. So never mind. It was a lame request anyway. I’ll take care
   of it. Thanks for replying!
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years ago](https://wordpress.org/support/topic/missing-argument-2-on-a-custom-function/#post-9129071)
 * Sorry it took me so long, but I didn’t forget!
    [https://core.trac.wordpress.org/ticket/40757](https://core.trac.wordpress.org/ticket/40757)

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

The topic ‘“Missing argument 2” on a custom function’ is closed to new replies.

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 6 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [9 years ago](https://wordpress.org/support/topic/missing-argument-2-on-a-custom-function/#post-9129071)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
