Title: Adding form code to sidebar.php
Last modified: August 21, 2016

---

# Adding form code to sidebar.php

 *  Resolved [jjrocket](https://wordpress.org/support/users/jjrocket/)
 * (@jjrocket)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/adding-form-code-to-sidebarphp/)
 * I want to add a custom search form within a custom sidebar. For some reason the
   form code does not show up when I add it to sidebar-custom.php. The form code
   does show up when I add it to page.php or some other file. It’s probably a simple
   php thing.
 * Here is my custom search form, very standard code:
 *     ```
       <form id="searchform" action="<?php bloginfo('url'); ?>/" method="get">
       <input class="inlineSearch" type="text" name="s" value="Enter a keyword" onblur="if (this.value == '') {this.value = 'Enter a keyword';}" onfocus="if (this.value == 'Enter a keyword') {this.value = '';}" />
       <input type="hidden" name="post_type" value="portfolio" />
       <input class="inlineSubmit" id="searchsubmit" type="submit" alt="Search" value="Search" />
       </form>
       ```
   
 * Here is my sidebar-custom.php, just like regular sidebar stuff:
 *     ```
       <?php
   
       if ( is_active_sidebar( 'inv-sb' ) ) : ?>
       	<aside id="secondary" class="sidebar-container" role="complementary">
       		<div class="sidebar-inner">
       			<div class="widget-area">
                                  <?php dynamic_sidebar( 'inv-sb' ); ?>
       			</div>
       		</div>
       	</aside><!-- #secondary -->
       <?php endif; ?>
       ```
   
 * I’ve tried adding the form code in a few different spots in the sidebar-custom.
   php without getting it to work. This doesn’t work:
 *     ```
       <?php
   
       if ( is_active_sidebar( 'inv-sb' ) ) : ?>
       	<aside id="secondary" class="sidebar-container" role="complementary">
       		<div class="sidebar-inner">
       			<div class="widget-area">
       <form id="searchform" action="<?php bloginfo('url'); ?>/" method="get">
       <input class="inlineSearch" type="text" name="s" value="Enter a keyword" onblur="if (this.value == '') {this.value = 'Enter a keyword';}" onfocus="if (this.value == 'Enter a keyword') {this.value = '';}" />
       <input type="hidden" name="post_type" value="portfolio" />
       <input class="inlineSubmit" id="searchsubmit" type="submit" alt="Search" value="Search" />
       </form>
                                  <?php dynamic_sidebar( 'inv-sb' ); ?>
       			</div>
       		</div>
       	</aside><!-- #secondary -->
       <?php endif; ?>
       ```
   
 * I want that custom form code to appear within the sidebar-inner div.

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

 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/adding-form-code-to-sidebarphp/#post-4756404)
 * Your code tests fine on my installation. Do you see any errors in your server
   logs? Are you calling in your custom sidebar template correctly? If your file
   name is `sidebar-custom.php`, then you need to call `get_sidebar( 'custom' );`
   or WordPress won’t load the right file.
 *  Thread Starter [jjrocket](https://wordpress.org/support/users/jjrocket/)
 * (@jjrocket)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/adding-form-code-to-sidebarphp/#post-4756426)
 * That was the problem – it works now! Thank you.

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

The topic ‘Adding form code to sidebar.php’ is closed to new replies.

## Tags

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

 * 2 replies
 * 2 participants
 * Last reply from: [jjrocket](https://wordpress.org/support/users/jjrocket/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/adding-form-code-to-sidebarphp/#post-4756426)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
