Title: Stupid syntax question: function within if else
Last modified: August 20, 2016

---

# Stupid syntax question: function within if else

 *  [Modifiedcontent](https://wordpress.org/support/users/modifiedcontent/)
 * (@modifiedcontent)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/stupid-syntax-question-function-within-if-else/)
 * This produces a syntax error (unexpected T_VARIABLE):
 *     ```
       if (... stuff ...) {
       wpmu_create_blog($domain, $path, $title, $user_id);
       } else if ...
       ```
   
 * How do you run a function within if else?

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/stupid-syntax-question-function-within-if-else/#post-2877347)
 * can you paste the full code, of whatever template that snippet belongs to, into
   a [http://pastebin.com/](http://pastebin.com/) and post the link to it here?
 * per se, the posted code is too short and taken out of context.
 * in general, [http://php.net/manual/en/control-structures.elseif.php](http://php.net/manual/en/control-structures.elseif.php)
 *  [Jam Viet](https://wordpress.org/support/users/mcjambi/)
 * (@mcjambi)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/stupid-syntax-question-function-within-if-else/#post-2877349)
 * function in if…else clause is okey ! but in detail ?
 *  Thread Starter [Modifiedcontent](https://wordpress.org/support/users/modifiedcontent/)
 * (@modifiedcontent)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/stupid-syntax-question-function-within-if-else/#post-2877353)
 * Thanks for your response. Here is more context:
 *     ```
       $user_id = $curauth->ID;
       $title = $curauth->display_name;
       $domain = network_home_url();
       $path = $curauth->user_login;
       $key = 'primary_blog';
       $single = true;
       $primary_blog = get_user_meta( $user_id, $key, $single);
   
       if ($primary_blog == "") {
       wpmu_create_blog($domain, $path, $title, $user_id);
       } else if (user_can_for_blog($user_id, $primary_blog, edit_posts )) {
       echo '<p>Member has site</p>';
       }
       ```
   
 * I know the general if else structure, but examples always use echo or ‘some code
   to execute’. I can’t find any examples with functions with variables.
 * I have tried ‘return wpmu_create_blog(…’ and other variations. Nothing works.
   And maybe this is a WP specific thing?
 *  Thread Starter [Modifiedcontent](https://wordpress.org/support/users/modifiedcontent/)
 * (@modifiedcontent)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/stupid-syntax-question-function-within-if-else/#post-2877533)
 * Can anyone give a general answer to this?
 * I can’t get any function within if/else to work, even when I try something basic
   like this:
 *     ```
       if(...) {
       wp_redirect( home_url() );
       exit;
       } else {
       ...
       }
       ```
   
 * I keep getting server/syntax errors – unexpected T_STRING etc. Shouldn’t this
   just work?

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

The topic ‘Stupid syntax question: function within if else’ is closed to new replies.

## Tags

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

 * 4 replies
 * 3 participants
 * Last reply from: [Modifiedcontent](https://wordpress.org/support/users/modifiedcontent/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/stupid-syntax-question-function-within-if-else/#post-2877533)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
