Wordpress Sidebar Contact Form

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>

<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!

 

14 Responses

  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 ๐Ÿ˜€

  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

  5. Gabriel says:

    IT WORKS!!!! THANKS!!!!

  6. Steve says:

    Thanks so much for this. Simple and very helpful.

  7. Stephen says:

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

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

  9. Adam says:

    Hi this has not been tested on 3+ Sorry!

  10. rich says:

    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

  11. Zagit says:

    This is mental. Why is it so complex to get a contact form in a sidebar?!

    Install a plugin, generate a form, include in a post, hide the post, and hack the sidebar.php page… I’d rather shoot myself.

    But sadly, most of the other contact form widget plugins suck as well.

    Is there a clever PHP dev out there that would be kind enough to code a simple and easy contact widget??? Please!!

  12. Adam says:

    What you want is something like GravityForms, theres a link to the right of the page, use that one to support me please ๐Ÿ˜‰

    Anyway, gravity forms is by far the best Contact Form management plugin avaliable for WordPress, I’ve got the big developer package and I include it with every single site I create for customers, its easy to use, has an API, Form Logic and Auto responders to name a few!

  13. Adam says:

    Try gravity forms, here’s a link top right of the page its not free but its awesome and has loads of plugins for it like paypal or use em to create a new user, its brilliant!

Leave a Reply

Your email address will not be published. Required fields are marked *