WordPress Sidebar Contact Form

Post 73 of 80

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

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!


, ,

Advertise Here


Chas BarberMarch 8, 2010 at 9:01 pmReply

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?

Chas BarberMarch 8, 2010 at 9:18 pmReply

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/


adminMarch 17, 2010 at 12:47 pmReply

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

BjornApril 7, 2010 at 4:18 pmReply

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

GabrielAugust 13, 2010 at 7:08 pmReply


SteveSeptember 24, 2010 at 12:46 pmReply

Thanks so much for this. Simple and very helpful.

StephenJune 13, 2011 at 7:07 pmReply

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 ?


StephenJune 13, 2011 at 7:09 pmReply

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

AdamJune 15, 2011 at 11:05 amReply

Hi this has not been tested on 3+ Sorry!

richAugust 15, 2011 at 2:11 pmReply

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

ZagitMay 21, 2012 at 4:06 pmReply

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

AdamJune 2, 2012 at 1:42 pmReply

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!

AdamFebruary 6, 2013 at 11:43 pmReply

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!

How to Add a WordPress Sidebar Contact FormAltered Advice | Altered AdviceAugust 3, 2012 at 3:39 amReply

[…] http://www.itsadam.co.uk/wordpress-sidebar-contact-form/ […]

Advertise Here