Posted on Leave a comment

The Ultimate Guide To Create Contact Form On WordPress

contact form on wordpress

Creating contact form is super easy in WordPress. Do a simple search and you can find tons of plugins available with 4.5+ star rating. You think that why do you need another tutorial, right? Well, for most people those plugins will work right out of the box and they can move on doing other important things. For some others, things are not so easy.

Maybe you have followed some tutorials, setup exactly as they said but still, the form doesn’t work. In other cases, you may want to add some tweaking to the look and feel of the form.

Whatever your reasons, my goal is to help you setup contact form for your website from scratch and make it work so you never miss an important message from your visitors.

Let’s get started.

Plugins to use

Before we begin, let’s have the following plugins ready:

  1. Contact Form 7 (required)
  2. Easy WP SMTP (required)
  3. Super simple grid (my plugin, optional if you want to have multiple columns form)
  4. Recaptcha V2 For Contact form 7 (optional but recommended)

Step 1: Create a contact form with contact form 7

The first step is to create a contact form with Contact form 7. You should have contact form 7 installed and activated for now.

If you look at your dashboard menu on the left, there should be an option called Contact:

The Ultimate Guide To Create Contact Form On WordPress 1

Click on that option, you’ll see contact form 7 screen:

The Ultimate Guide To Create Contact Form On WordPress 2

As you can see, there is already a form created for you. Go ahead and delete it as we are going to create a new form.

Click on the add new button at the top to add a new form.

The Ultimate Guide To Create Contact Form On WordPress 3

As you can see, there are three main things we are going to do with Contact form 7:

  1. Enter a form name (nearly the easiest thing)
  2. Add, remove fields to your form (hardest)
  3. Click on Save button to save your form (the easiest)

As the form name, you can enter anything you like. In case you need to have multiple contact form, the name should help you tell which for is which.

Now, let’s go ahead to configure the fields of our form.

Normally, a contact form should have the following fields:

  1. Contact name
  2. Contact email
  3. Subject
  4. Message

However, you can add more fields if you need to.

Contact form 7 support a variety of fields as you can see at the top of the form editor:

The Ultimate Guide To Create Contact Form On WordPress 4

As you can see, you can even add radio, checkboxes and even quizzes to the contact form, which is very great.

To add any field to your form, first, put the cursor where you want to insert the field, then click on the field you want to insert.

For example, I want to insert a confirmation checkbox below the message box, I click on the space below that message box:

The Ultimate Guide To Create Contact Form On WordPress 5

Then, click on acceptance button at the top:

The Ultimate Guide To Create Contact Form On WordPress 6

Configure the field before adding to your form

A window will show up for me to configure the field:

The Ultimate Guide To Create Contact Form On WordPress 7

There are a few things you need to pay attention to:

  1. Name: this should be human readable and it should tell you what the field is about. If you are adding a telephone field (tel), then you should name it tel, phone…
  2. Id and class: These fields are useful if you want to style them using CSS later. If you are happy with the default, leave them blank.
  3. Condition: this option is specific to acceptance field only
  4. Options: This option is specific to acceptance. In other fields, you will have the required checkbox to mark the field cannot be blank when submitting form.

Now, I have the form ready. I’m going to save it. After saving the form, there is a field appears:

The Ultimate Guide To Create Contact Form On WordPress 8

This is the shortcode. You can think of shortcode as a placeholder for a, usually, much bigger text. In this case, it’s our form.

This is the code we put in the contact page to display the contact form. Thus, let’s go ahead and put this code in a page.

If you are using Gutenberg editor, you should add a shortcode element first before putting the shortcode:

The Ultimate Guide To Create Contact Form On WordPress 9

In case you use the classic editor, you just paste the code in the page’s body.

Let’s publish the page and take a look at our form:

The Ultimate Guide To Create Contact Form On WordPress 10

As you can see, the form looks great and it has all the fields as added in contact form 7 form builder.

Step 2: Configure SMTP server to ensure mail delivery

Nowadays, most hosting providers offer mail function out of the box for PHP (the programing language behind WordPress). As a result, many of you may not have any problem get the contact message delivered to your inbox. However, if you have built your contact form, tried to submit a message but still didn’t see anything in your inbox, it’s time to configure your SMTP server.

Don’t worry about the jargons, it is very simple to fix mail sending problem in WordPress as I made a tutorial here:

The tutorial is for WooCommerce but it works for WordPress too.

Step 3: Put your form in multiple columns

Now you should have the form up and running. When someone submit the form, you should get a message in your inbox. That’s great!

However, what if you want to put the form in multiple columns? No worries, I got you covered!

Here is the detailed tutorial on how to put contact form 7 in multiple columns.

Step 4: Add recaptcha v2 to your form to prevent spam

Spam is a serious problem that any site owner has to face today. When you put up a form, you open a door to your inbox for spammer. Thus, adding captcha to your form is a great way to keep your inbox clean.

Now, let’s add the plugin Recatpcha V2 For contact form 7 to your site.

After you activate the plugin, you’ll see a new option under Contact form 7 menu:

The Ultimate Guide To Create Contact Form On WordPress 11

Click on that to start setting up Recaptcha.

The Ultimate Guide To Create Contact Form On WordPress 12

Select the options as in the screenshot and click on submit.

You are done on that screen. However, there in one extra step you need to do to make recaptcha works. That is integrate recaptcha with your site.

Still under Contact menu, click on Integration:

The Ultimate Guide To Create Contact Form On WordPress 13

You’ll see there is a box says reCaptcha. Click on setup integration button in that box to start integrating it to your site:

The Ultimate Guide To Create Contact Form On WordPress 14

The next screen is where you put reCaptcha keys:

The Ultimate Guide To Create Contact Form On WordPress 15

You may wonder, where do I get those keys? Don’t worry, I’ll walk you through that.

First go to this url:

https://www.google.com/recaptcha/admin/create

If you are not logged in to your gmail account, login first and try visiting that page again. You’ll see a screen like this:

The Ultimate Guide To Create Contact Form On WordPress 16

There are two recaptcha options at the time of this writing: v2 and v3. You should select v2, not v3 for this to work.

Make sure you add your domain at “add a domain, e.g. example”

Finally, click on Submit to finalize the process. As a result, you’ll see the keys available in the next screen:

The Ultimate Guide To Create Contact Form On WordPress 17

Now, copy them to put in the integration screen on your blog and you are done.

The Ultimate Guide To Create Contact Form On WordPress 18

Click on save changes to save the keys.

Now, there is one more thing you need to do. That is putting [recaptcha] tag to the contact form so the captcha will show up.

The Ultimate Guide To Create Contact Form On WordPress 19

And when I view the form, sure enough, recaptcha box is there:

Recaptcha is working on contact form 7 form

Conclusion

As you can see, setting up contact form on WordPress could be quite tricky. However, with the helps of plugins, it is much easier to create fully functional contact page. Hopefully the tutorial is helpful to you. If you need further assistance, don’t hesitate to drop me a message.

Posted on Leave a comment

How To Fix “Fatal Error: Allowed memory size of … bytes exhausted” In WordPress

How To Fix "Fatal Error: Allowed memory size of ... bytes exhausted" In WordPress 20

Setting up your WordPress blog is easy. With an affordable hosting, you can have you site up in just a few minutes. When you first start out, your site may have little traffic and it runs smoothly. However, when your site get popular and you get more traffic, you may encounter this message when you open your site:

How To Fix "Fatal Error: Allowed memory size of ... bytes exhausted" In WordPress 21

You cannot view your beautiful site anymore and so as your visitors. What is the cause and what can you do to fix it?

What is the cause of Allowed memory size of … bytes exhausted?

As the error message suggests, your WordPress site has used up all the allowed memory. For example, your server settings allocated 32MB for your site to run. However, due to high amount of traffic to your site, it used up all the 32MB. Thus, there is no more memory left for your site to continue running. That’s the reason why you see that message.

How to fix this problem?

As you can see, the cause is lack of memory so the fix should be to increase the amount of allowed memory for WordPress to run. It sounds very simple, however, it is not always the case.

Why so?

The reason is this problem usually occurs on cheap hosting, where the hosting providers usually allocate a small amount of RAM for their users. You must ask your hosting provider to increase the allowed memory for your WordPress site. If they don’t agree to do so, you are out of luck.

However, in case they agree to increase your memory limit, you can do the following steps to give your site more memory to run.

  1. Going to your site by using cPanel/FTP/SSH
  2. Open wp-config.php
  3. Put this line:

define( ‘WP_MEMORY_LIMIT’, ’64M’ );

right above the part says: /* That’s all, stop editing! Happy blogging. */

You can replace the number 64 to a higher one if allowed. For a blog that gets a lot of traffic, you may need to set the limit to 512M or even more.

Then, save the wp-config.php file and you are done. Your WordPress site now have more memory to operate. Make sure to monitor your site closely to see if you still have this error. If you still get this error, you can increase the limit once again. In case the memory limit that your hosting provider gives you is low, you should consider upgrading your hosting plan to a VPS.

 

Posted on Leave a comment

How To Add New Currency To WooCommerce

How To Add New Currency To WooCommerce 22

Woocommerce comes with quite many currencies. In fact, if you are selling items internationally, you got a plenty of options to choose from such as USD, GBP, EUR or even BTC (bitcoin). However, there are a lot of currencies isn’t in that list. For example, what if you want to accept ETH (Ethereum) as your currency? Don’t worry, we can make that work.

Check if your currency is supported by Woocommerce

Woocomemerce is updated frequently. Thus, chances are your currency get added in the latest release. The first thing you need to do is to:

  1. Update Woocommerce to the latest version
  2. Go to Woocommerce->Settings->General->Scroll to the bottom to see the currency options. You can see the list of supported currencies there

If your desired currency is in the list, that’s great! You don’t need to do anything else. If it isn’t, read on.

Introducing the necessary hooks

If you are unfamiliar with the term hooks, you can take a look at the official document here. However, it is not necessary to understand it thoroughly to add new currencies to Woocommerce.

There are two filter hooks you need to use to add new currency to Woocommerce

  1. woocommerce_currencies
  2. woocommerce_currency_symbol

As the names suggest, the first one will be used to register new currency and the second one will be used to register the currency’s symbol.

The actual code

I’m going to register the Ethereum currency to Woocommerce. However, you can define and add any type of currency you want. You can even invent a currency that isn’t available right now.

add_filter( 'woocommerce_currencies', 'bc_add_new_currency' );
add_filter( 'woocommerce_currency_symbol', 'bc_add_new_currency_symbol', 10, 2 );

function bc_add_new_currency( $currencies ) {
     $currencies['ETH'] = __( 'Ethereum', 'your-theme-text-domain' );
     return $currencies;
}


function bc_add_new_currency_symbol( $symbol, $currency ) {
     
     if( $currency == 'ETH' ) {
          $symbol = '♦';
     }
     return $symbol;
}

There are a few places in the code above you need to pay attention to:

  1. The symbol of ETH is ♦. You can replace this with your currency’s symbol .
  2. Name of your currency. In the code, it is “Ethereum”. You can change this to the name of your currency. For example: Bitcoin Cash
  3. The index key ‘ETH’. This can be anything but unique across all currencies.

Now, after you modify the code to match your currency of choice, put it at the end of the functions.php file in your active theme folder:

How To Add New Currency To WooCommerce 23

The result

Now, if you go to Woocommerce->Settings->General and scroll down to Currency Options, you can search for the new currency:

How To Add New Currency To WooCommerce 24

That’s it! That’s how you can add new currencies to Woocommerce. You can add as many new currencies as you want, there is no limit.

Posted on 3 Comments

How To Use Visual Composer In The Category Page

Visual Composer is a very popular plugin to visually create your content. There are many widgets, components in the plugin. In addition, there are other plugins that add more functionalities and widgets to Visual Composer make it the love of many WordPress users.

However, Visual Composer can only be used on regular pages/posts. If you want to use it to create content for your category page, you are out of luck. Visual composer doesn’t support creating content for the category page.

In case you don’t know where to put content on your category, here it is:

How To Use Visual Composer In The Category Page 25

 

As you can see, there is a text editor for you to put the content, descriptions for the category but that’s it. There is no visual composer editor available.

So, how can you enable visual composer in the category page?

Meet the plan

Our plan is quite simple. Instead of putting the content directly into the editor of the category page, we will create a draft post and then display the content of that draft post as the content of the category page.

Why a draft post?

Because you don’t want your visitor to see this post since it’s not a independent post by itself. The sole purpose of this post is to contain the content for the category page.

As a post, you can use all the features of Visual Composer to compose its content.

Let’s look at a diagram, shall we?

How To Use Visual Composer In The Category Page 26

Now, let’s get to the step by step implementation.

Step-by-step to use Visual Composer to create content for your category page

  1. Create the content of your category page in a regular post using Visual Composer
  2. Save that regular post as a draft
  3. Get the draft post’s ID
  4. Install Display Posts Shortcode plugin
  5. Find out what theme your site is using
  6. Create a template file for your category page
  7. Display the content of the draft post in your category using shortcode

I assume that you are familiar with the steps 1 and 2. Creating a post and save it as a draft are quite trivial so I won’t explain in details here.

Step 3: Get a post’s ID

After creating the draft post, make sure you get the post ID and save it somewhere. You can get the post ID of any post by following the instructions below:

 

Step 4: Install Display Posts Shortcode plugin

You can navigate to Plugins->Add new and search for this term: Display Posts Shortcode and install the one as in the image below:

How To Use Visual Composer In The Category Page 27

 

Step 5: Find out what theme your site is using

This step is quite simple, please go to Appearance->Themes and you will see what theme is currently active. We need to know this information for the next step.

Step 6: Create a template file for your category page

This step sounds scary for people who don’t know how to code. However, it is very simple. You need to access to your themes folder on your server to complete this step. You can access the files via cPanel or FTP or ssh. Please ask your hosting provider for those details. All hosting providers should have no problem sending you those details.

Here I use Filezilla FTP client to access my files. Please go to wp-content/themes on your sever.

In the previous step, I found out that my site is currently using the theme Blog One, I can see the folder of that theme here:

How To Use Visual Composer In The Category Page 28

I will click inside that folder to see all the files:

How To Use Visual Composer In The Category Page 29

 

Here, we pay close attention to the one file called single.php. We are going to create a template file for the category using that file.

Now, go find your category ID. The method is similar to finding post’s ID.

  1. Go to Posts->Categories
  2. Hover on the Edit link of your category
  3. Look at the status bar of your browser (bottom left)
  4. Locate the tag_ID value

And that’s your category ID.

For example, my Blog category ID is: 1

How To Use Visual Composer In The Category Page 30

 

Now, copy the single.php file and name it category-1.php (if your category ID is 300, you need to create a file called category-300.php);

 

If you use an FTP client such as FileZilla, you need to download the single.php to your computer first, then rename the file to the new name.

Open the file with your favorite text editor. On Mac, you have Sublime text. I use Notepad++ since I’m on Windows.

How To Use Visual Composer In The Category Page 31

Your file may be a bit different, however, it will look something like that.

Now, we need to remove the content of the file from the <?php to ?> in the image above:

How To Use Visual Composer In The Category Page 32

Then, put the following code right at the place where you have just removed the old content:

How To Use Visual Composer In The Category Page 33

Make sure you replace the your_draft_post_ID with the actual draft post ID you got from above.

Now, upload the file to your theme folder (sample folder with the single.php) and you are done.

Now, what you put in the draft post will appear on your category page.

One last thing, please NEVER publish the draft post.

I hope this post has been helpful. Now you can use Visual Composer to create content for your category page.

Update: You can use this method with any page builder, not just Visual Composer. I’ve made a video here demonstrating how I used Elementor to create and display a custom design for my category page: