Recently, one of our users asked us how to add autocomplete for address fields in WordPress forms. Autocomplete allows users to quickly select address from suggestions generated in realtime as they type. In this article, we will show you how to add autocomplete for address fields in WordPress using Google Places API.
If you donβt like the video or need more instructions, then continue reading.
First thing you need to do is install and activate theΒ Address Autocomplete Using Google Place ApiΒ plugin. For more details, see our step by step guide onΒ how to install a WordPress plugin.
Upon activation, you need to visitΒ Settings Β» Google AutocompleteΒ page to configure plugin settings.
You will be asked to enter Google Places API Key. This API key allows your website to connect with Google Maps and retrieve autocomplete suggestions from their database in realtime.
Head over toΒ Google Developer ConsoleΒ website and create a new project.
A popup will appear asking you to provide a name for your project. Use a name that will help you later identify the project and then click on the create button.
The popup will disappear, wait for a few seconds and you will be automatically redirected to your new project.
Now you will see the list of popular Google APIs that you can enable for your project. You need to locate and click on βGoogle Places API Web Serviceβ.
This will take you to an overview page explaining how this API works. You need to click on the Enable link to continue.
Developer console will now enable Google Places API for your project.
However, you will still need credentials to use the API on your website. So go ahead and click on the create credentials button to continue.
On the next screen, you need to click on βWhat credentials do I need?β button.
Developer console will now show you the API key. You need to copy this key and paste it under the plugin settings on your WordPress website.
You still need to enable another API on your Google Developers project. Click on the library in Google Developer Console and then click on βGoogle Maps JavaScript APIβ.
This will take you to APIβs overview page where you need to click on the βEnableβ link to continue.
This API doesnβt need an extra API key, so you are now good to go.
Enabling Autocomplete Address in WordPress Form Fields
You can add autocomplete address feature to any form field created by anyΒ WordPress form builder plugin.
We will be usingΒ WPFormsΒ in this tutorial. However, these instructions will work no matter what contact form plugin you are using.
First you need to create a form that has an address field or a set of address fields.
Once you are done, add this form to your website like you would normally do.
Next, go to the post or page where you added your form. You need to right click the address field and select βInspectβ from browser menu.
Donβt forget to click on the save button to store your changes.
Thatβs all, you can now visit your form page and try entering an address. The form field will automatically start showing suggestions using Google places andΒ Google Maps.
We hope this article helped you learn how to add autocomplete for address fields in WordPress. You may also want to see our list ofΒ 24 must have WordPress plugins for business websites.
If you liked this article, then please subscribe to ourΒ YouTube ChannelΒ for WordPress video tutorials. You can also find us onΒ TwitterΒ andΒ Facebook.