Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressで住所フィールドにオートコンプリートを追加する方法

編集メモ: WPBeginner のパートナーリンクから手数料を得ています。手数料は編集者の意見や評価に影響を与えません。編集プロセスについて詳しく知る。

WordPressの住所欄にオートコンプリートを追加したいですか?

最近、あるユーザーから WordPress フォームの住所フィールドにオートコンプリートを追加する方法を尋ねられました。オートコンプリートを使用すると、ユーザーは入力中にリアルタイムで生成される候補から住所をすばやく選択することができます。

この投稿では、Google Places APIを使ってWordPressの住所フィールドにオートコンプリートを追加する方法を紹介する。

How to Add Autocomplete for Address Fields in WordPress

WordPressにオートコンプリート・フィールドを追加する理由

WordPressにオートコンプリートのアドレスフィールドを追加することで、サイトのユーザーエクスペリエンスを向上させることができます。

例えば、eコマースストアを経営している場合、カスタマイザーは住所をより速く入力することができ、タイプミスを防ぐことができます。

買い物客が住所を入力すると、現在地から考えられる住所が画面に表示されるので、買い物客は正しい住所を選ぶだけでよい。ユーザーに表示されるオプションはGoogle PlacesやGoogle Maps APIと連携しているため、エラーを減らすことができる。

アドレスフィールドのオートコンプリートは、ユーザーに提供できる最も便利な機能の1つです。購入手続きを素早く行うことができれば、購入に至る可能性が高くなります。

各購買を迅速かつシンプルにすることで、売上を向上させ、たまに買い物をする人を定期顧客にする可能性が高くなる。

WordPressにオートコンプリートのアドレスフィールドを追加するメリットをご理解いただけたところで、ステップ・バイ・ステップでその方法をご紹介します。

動画チュートリアル

Subscribe to WPBeginner

動画が気に入らなかったり、もっと説明が必要な場合は、このまま読み進めてください。

まず最初に行う必要があるのは、オートコンプリートGoogleアドレスプラグインを インストールして有効化することです。

Autocomplete Google Address plugin

詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。

有効化した後、WordPressダッシュボードの設定 ” オートコンプリートページにアクセスしてプラグイン設定を行う必要があります。

Autocomplete WordPress

Google Places API Keyの入力を求められます。このAPIキーにより、あなたのサイトがGoogleマップに接続し、Googleマップのデータベースからオートコンプリート候補をリアルタイムで取得できるようになります。

Google Places APIキーにアクセスする

Google Developer Consoleのサイトにアクセスし、新規プロジェクトを作成します。

Google Console create a project

プロジェクトの名前を入力するページが表示されます。

後でプロジェクトを識別するのに役立つ名前を付けて、「Create」ボタンをクリックします。接続したい組織がある場合は、’Browse’リンクをクリックするとオプションのドロップダウンが表示されます。

Create a project in Google Console

数秒待つと、API & Servicesページに自動的にリダイレクトされます。

ここから左サイドパネルに移動し、「ライブラリ」タブをクリックする。

Library in Google Console

プロジェクトで有効化できる一般的なGoogle APIのリストが表示されます。左のパネルで’Maps’を選択し、マップに関連するオプションのみでフィルターをかけます。

Places API’オプションを見つけてクリックする必要がある。

Places API

そこから、Places APIの概要ページが表示されます。

有効化」ボタンをクリックするだけで、APIが認可されます。

Enable Places API

Google Consoleが正しく設定されていれば、API Keyのポップアップウィンドウが表示されるはずです。

ただし、Google Consoleアカウントを初めて設定する場合は、請求先情報を入力する必要があります。

Copy API Key

これでWordPressサイトに戻ることができる。

Google ConsoleのAPIキーを’Google Place API Key’と表示されている場所に貼り付けます。

Google Place API Key

WordPressで住所のオートコンプリートが機能するようにするには、Google Maps JavaScript APIを有効化する必要があります。

そのため、Google Developer Consoleのダッシュボードから「API & Services」タブに戻るだけでよい。そして、「Maps JavaScript API」を見つけて、「有効化」をクリックする。

Enable maps javascript API

これで、フォームIDの追加に移る準備ができました。

次のステップでは、住所のオートコンプリート機能を追加したい住所フィールドのフォームIDが必要です。

WordPressのフォームフィールドでアドレスのオートコンプリートを有効化する

WordPress フォームビルダープラグインで作成されたフォームフィールドにオートコンプリート機能を追加することができます。

このチュートリアルではWPForms を使用します。WPFormsはドラッグ&ドロップでフォームを作成できる最も優れたプラグインで、初心者にも使いやすいからです。しかし、どのお問い合わせフォームプラグインを使用していても、このチュートリアルは有効です。

まず、住所フィールドまたは住所フィールドのセットを持つフォームを作成する必要があります。

完了したら、通常と同じようにWordPressサイトにこのフォームを追加します。

次に、フォームを追加した投稿またはページに行きます。アドレスフィールドを右クリックし、ブラウザーメニューから「Inspect」を選択する必要があります。

Inspect button

ここでは、入力フィールドのフォームID値がハイライトされた部分が表示されます。

例えば、このスクリーンショットでは、フォームのID値はwpforms-567-field_4です。

Form ID in developer tool

この値をコピー&ペーストしてプラグイン設定ページに貼り付けてください。

しかし、住所フォーム全体にオートコンプリート機能を追加したいでしょう。例えば、ユーザーが配送先住所全体をオートフィルできるようにしたかった場合、市町村、番地、郵便番号をオートフィルする必要があります。

この場合、「Inspect」をクリックし、各フィールドのフォームIDを見つけて、同じプロセスを踏む必要がある。

Form ID in WordPress

IDをすべて取得したら、オートコンプリートページの「フォームID」と書いてあるところにコピーしてください。

複数のIDを追加する場合は、以下のように各IDをコンマで区切り、引用符で囲む必要があります。入力が終わったら、忘れずに「変更を保存」を押してください。

Multiple autocomplete address values

これですべてです。フォームページにアクセスして、住所を入力してみてください。

フォームフィールドは自動的にGoogleプレイスとGoogleマップを使用した提案を表示し始めます。

address autocomplete

これで Google アドレスオートコンプリート機能がフォームに追加されました。ユーザーがWooCommerce ストアでチェックアウトする場合でも、ユーザー登録のサインアップを完了する場合でも、フォームに自動入力できるようになります。

WordPressで住所欄にオートコンプリートを追加する方法について、この投稿がお役に立てば幸いです。ビジネスサイトに必須のWordPressプラグイン24個のリストや、メールマガジンの作成方法についてのガイドもご覧ください。

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.

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

23件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

    • WPBeginner Support says

      Thank you for letting us know, we’ll be sure to take a look and find an alternative.

      管理者

    • WPBeginner Support says

      Hi Vinod,
      Sadly, for that customization, you would need to reach out to the plugin’s support for if they currently support multiple fields

      管理者

  2. Mooki says

    It works thanks, I had searched of websites and plugins and nothing worked until I got to this helpful site

  3. Fabiano Hirtz says

    I have a travel site, tours and transfers, I would like to install this tool, when the client selected the place of visit and the arrival was not transferred, or tour, but it is not a contact form, but rather a search form, does it work? I put the class, did everything correctly, it still does not work. Can someone help me?

  4. Jay Kuntal says

    Hey, I tried a lot with getting API. It works fine when i use custom code from google on code pen. But when i put the same API on this plugin, it doesn’t work.

    I have enabled two APIs – Places Web and Maps JS with credentials on Places Web.

    What am i missing here

    Thanks

  5. Tess says

    Curious to know how to set a default country to appear first (instead of the default US addresses). Do you have any idea if there is a shortcode or some way to do this with this plugin?

    BTW, I got the plugin working by just adding into the “Name” field. It works fine for me apart from wanting it to show AU addresses first. :)

  6. asima says

    How to populate the ‘current location’ in ‘area/neighborhood ‘ select dropdown as the first select option (rest of the options coming from the database) ?

  7. steve hajjaj says

    Hi there thanks for the article. I have followed the process you described but I still cannot get autocomplete to work at all. Is there something wrong with my google developers account ? as I can see the 2 APIs are enabled but cannot see any requests. Thanks

  8. Luke says

    I found a bug. When you type in the name of the business, the auto-completed address does NOT include the street number, only the street name (Main St, not 123 Main St). Big problem!!!

  9. Sarah says

    If there is one thing we are mindful; it’s the ‘mission creep’ of Google into websites and related app areas.

    Where able, we try not to engage google into our sites so as to remain ‘in control’ in what we do.

    But thanks for the insight …

  10. Camilo says

    Can it be possible to have the autocomplete fill out the zipcode, state and country as well? I just followed everything here and the address populates automatically but the user still has to manually input their zip code, state, and city

  11. Zafar Rathore says

    Excellent article for autocomplete. I was looking for such a easy to go method and you guys made it.
    Autocomplete really saves a lot of time for end users which ultimately contributes to user friendly environment.

    Keep it up guys.
    Thank you

  12. Nicholas Johnson says

    I’m planned to create WP form with autocomplete, but I don’t know how to do that. After reading this post, I have an idea to create auto-complete forms.

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。