WordPress Sidebar Contact Form

sidebarcontactusEveryone at some point needs to have a sneaky little contact form in their sidebar, It’s a total ballache when customers want to be able to change it too.



So heres how we’re going to do this, what you’ll need is:

  • A WordPress Install
  • FTP Details (If plugins do not auto install)
  • A Contact Form Plugin (Contact Form 7 I’ll be using)
  • WP Hide Post Plugin
  • 5 minutes of time

So we’re all ready? You will be kicking yourselves at how simple this will be.

First we install the plugins so:
Plugins > Add New > Search > Contact Form 7
Plugins > Add New > Search > WP Hide Post

And then install them.

Once you are done, click the new *Contact* button newly added to the bottom left of your wordpress nav.

After you have finished doing your shiny contact form copy the code.

It should look something like this:

[contact-form 1 "Contact form 1"]

Then goto:
Posts > Add New

Name it something like “SIDEBAR CONTACT FORM”
Paste  your code in, on the WP Hide Post tick/cross all boxes to complete *hide* the post, and then click Publish as normal.

Hover over the post in the posts are to find its ID, ie
wp-admin/post.php?action=edit&post=12

So your post is #12 for this.

We need to then go here:

Appearance > Editor:  Then Click on: Sidebar (sidebar.php)

This will load up your sidebar.php file.

You then need to insert this code wherever you wish to have it show (ie at the top then right after the first <div id/class>

&lt;p&gt;Contact Us&lt;/p&gt;
&lt;!-- p= your post ID for the Contact form --&gt;
&lt;?php query_posts('p=12'); if(have_posts()) : the_post(); ?&gt;
&lt;?php the_content(); ?&gt;
&lt;?php endif; ?&gt;
&lt;br /&gt;

Save, and that’s it, you’re done.

You client can alter and amend this sidebar form as per usual, and leaves you with no nasty coding at all!

This way is tonnes better than people who use the same code but link to page, since the contact page may have other written content such as telephone numbers etc which you won’t want!

Enjoi!

, ,

10 Responses to WordPress Sidebar Contact Form

  1. Chas Barber March 8, 2010 at 9:01 pm #

    This is fantastic! Thanks for the contact form link and for this idea. It was just what I was looking for. One question, I’d like to put the form into my sidebar as a widget so that it shows up in the pretty boxes that my other widgets show up in. I tried just putting the code that you recommend to add to the sidebar page code, but that does not work. Any suggestions?

  2. Chas Barber March 8, 2010 at 9:18 pm #

    I figured out a solution. Found a plugin to execute PGP in the Widget Sidebar. Worked like a charm! http://www.hongkiat.com/blog/execute-php-in-wordpress-post-page-and-widget-sidebar/

    Thanks!

  3. admin March 17, 2010 at 12:47 pm #

    Hey that looks handy, thank’s for sharing, might have to give it a try soon :D

  4. Bjorn April 7, 2010 at 4:18 pm #

    Thanks alot for your help, i have been looking for a few days and you finally helped my finding a good contact form! It is really easy to implement so just do what this guy is saying! GOOD WORK

  5. Gabriel August 13, 2010 at 7:08 pm #

    IT WORKS!!!! THANKS!!!!

  6. Steve September 24, 2010 at 12:46 pm #

    Thanks so much for this. Simple and very helpful.

  7. Stephen June 13, 2011 at 7:07 pm #

    Hi, does this work with WordPress 3+ ? Can’t figure out what I’m doing wrong, but my sidebar is just displaying the code as follows:

    Contact Us

    Not showing the form fields. Any ideas ?

    Thanks!

  8. Stephen June 13, 2011 at 7:09 pm #

    (is displaying the HTML/PHP code which did not appear in my reply when pasted)

  9. Adam June 15, 2011 at 11:05 am #

    Hi this has not been tested on 3+ Sorry!

  10. rich August 15, 2011 at 2:11 pm #

    I keep getting this message

    Parse error: syntax error, unexpected ‘;’, expecting T_PAAMAYIM_NEKUDOTAYIM in /homepages/42/d363696523/htdocs/wp-content/themes/GreyScale/library/sidebars.php on line 5

Leave a Reply