Title: Code in a widget
Last modified: August 19, 2016

---

# Code in a widget

 *  [stargate03](https://wordpress.org/support/users/stargate03/)
 * (@stargate03)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-in-a-widget/)
 * Hi there
 * can someone give me an example of how to put code in a text widget for an if 
   else statement
 * i want it to say
 * if its page 4400 then show form A
 * else if its page 4401 then show form B
 * etc
 * forms are just standard forms

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-in-a-widget/#post-1227353)
 * Are these Posts or Pages? Where are the forms on the server?
 * You can’t use php in any of the native WP widgets but you could edit the relevant
   template file (such as sidebar.php) and add the code.
 *  Thread Starter [stargate03](https://wordpress.org/support/users/stargate03/)
 * (@stargate03)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-in-a-widget/#post-1227356)
 * Hi there
 * the forms are currently just in the text widget
 * how would i use php to place it in the sidebar, in order to determine if its 
   a certain page then show a certain form
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-in-a-widget/#post-1227362)
 * Two basis options:
 * 1. Add the markup for both forms to your sidebar and use what’s called a conditional
   to control what form is shown and when.
 * 2. Duplicate your sidebar, add the forms to Text widgets on different sidebars
   and then use a conditional to control what sidebar to show
 * Which would you prefer? You still didn’t confirm whether 4400 and 4401 are Posts
   or Pages…
 *  Thread Starter [stargate03](https://wordpress.org/support/users/stargate03/)
 * (@stargate03)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-in-a-widget/#post-1227363)
 * They are pages
 * if i use a conditional whats the code for that
 * i guess its something like
 * if ($postID = “4401”)
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-in-a-widget/#post-1227371)
 *     ```
       <?php if( is_single('4400') ) :?>
       [ do foo ]
       <?php elseif( is_single('4401') ) :?>
       [ do bar ]
       <?php endif;?>
       ```
   
 * [http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page](http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page)
 *  Thread Starter [stargate03](https://wordpress.org/support/users/stargate03/)
 * (@stargate03)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/code-in-a-widget/#post-1227379)
 * Thanks for that works great except the
 * is_single needed to be is_page
 * many thanks

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

The topic ‘Code in a widget’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [stargate03](https://wordpress.org/support/users/stargate03/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/code-in-a-widget/#post-1227379)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
