23 Sep 2009

WordPress Sidebar Contact Form

Cool Stuff, HTML, Website Design, Wordpress 4 Comments

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>

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

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!

4 Responses to “WordPress Sidebar Contact Form”

  1. Chas Barber says:

    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 says:

    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 says:

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

  4. Bjorn says:

    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

Leave a Reply