Title: Cannot Redeclare Function
Last modified: April 5, 2021

---

# Cannot Redeclare Function

 *  [imkevz](https://wordpress.org/support/users/imkevz/)
 * (@imkevz)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/cannot-redeclare-function-4/)
 * Hi I want to use a code snippet but I receive the error “Cannot redeclare function
   wpb_user_count.” How can I fix it?
 * Here’s the code:
 *     ```
       // Function to show the user count by role via shortcode
       function wpb_user_count($atts) {
       $atts = shortcode_atts( array(
       ‘role’ => ”
       ), $atts );
       $user_query = new WP_User_Query( array( ‘role’ => $atts[‘role’] ) );
       // Get the total number of users for the current query. I use (int) only for sanitize.
       $result = (int) $user_query->get_total();
       return $result;
       }
       // Creating a shortcode to display user count
       add_shortcode(‘user_count’, ‘wpb_user_count’);
   
       // Use this Shortcode to show user [user_count role=”Subscriber”]
       ```
   

Viewing 1 replies (of 1 total)

 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/cannot-redeclare-function-4/#post-14276906)
 * The message means that there already is a function defined called `wpb_user_count`
 * Why I don’t know, it is probably already defined in plugin.
 * The simple solution is use another function name e.g.
 *     ```
       // Function to show the user count by role via shortcode
       function longrandomstring123xyz_user_count($atts) {
       $atts = shortcode_atts( array(
       ‘role’ => ”
       ), $atts );
       $user_query = new WP_User_Query( array( ‘role’ => $atts[‘role’] ) );
       // Get the total number of users for the current query. I use (int) only for sanitize.
       $result = (int) $user_query->get_total();
       return $result;
       }
       // Creating a shortcode to display user count
       add_shortcode(‘user_count’, ‘longrandomstring123xyz_user_count’);
   
       // Use this Shortcode to show user [user_count role=”Subscriber”]
       ```
   
 * However, if it was my site I’d first investigate ( by searching the code in the
   plugin & themes directory ) what the other function `wpb_user_count` does.

Viewing 1 replies (of 1 total)

The topic ‘Cannot Redeclare Function’ is closed to new replies.

## Tags

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

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * Last activity: [5 years, 2 months ago](https://wordpress.org/support/topic/cannot-redeclare-function-4/#post-14276906)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
