To add address lookup to WordPress without a plugin, call AutoPostcode from server-side WordPress code and connect your own form to a protected endpoint. Keep the API key on the server and let visitors select an address or enter one manually.
What do you need before you start?
Create an AutoPostcode account and a website API key, then check the pricing and API quickstart. Keep your key on a server you control and do not commit it to source control.
1. Create a key and server configuration
Create a website key and provide it to PHP through your hosting environment. Use a child theme or maintained custom code, so a theme update does not erase the integration.
2. Request addresses from WordPress
This server-side PHP example uses WordPress HTTP helpers. It is a lookup example, not a complete public endpoint or form.
// Server-side PHP; configure AUTOPOSTCODE_API_KEY outside the web root.
$key = getenv('AUTOPOSTCODE_API_KEY');
$url = add_query_arg('postcode', 'SW1A 1AA',
'https://autopostcode.com/api/public/lookup');
$response = wp_remote_get($url, array(
'headers' => array('x-api-key' => $key), 'timeout' => 10,
));
if (is_wp_error($response)) { return; }
if (wp_remote_retrieve_response_code($response) !== 200) { return; }
$addresses = json_decode(wp_remote_retrieve_body($response), true);
// Offer the results for a user to select; never expose $key to the browser.
3. Connect your form
Build a same-origin server endpoint with input validation, rate limiting and appropriate access controls. Add a postcode input and accessible results selector; map the chosen result to your own address fields.
4. Test and maintain
Test empty and invalid input, 401, 402, 404, timeouts, manual entry and theme updates on a staging site before launch.
What should you check before switching over?
Use the API documentation and REST API reference for response fields and errors. Explore the postcode lookup API and address autocomplete API for the right search experience.
Frequently asked questions
Does this require an AutoPostcode API key?
Yes. Create a website key in the AutoPostcode dashboard and keep it on your server.
Can I test a full postcode before building the interface?
Yes. Send an authenticated GET to /api/public/lookup with the postcode parameter; successful responses contain an array of addresses.
What happens when no address is found?
The postcode lookup endpoint returns 404 when it finds no addresses. Show a clear message and allow manual entry.
Should the key be included in browser JavaScript?
No. Keep the key on your server and protect any endpoint that makes requests on the visitor’s behalf.
Does a postcode identify one address?
No. A postcode can identify several addresses, so let the visitor select the correct result.
How should errors be handled?
Handle invalid input, authentication failures, insufficient credit, no matches and timeouts; provide a manual-entry fallback.
We'll beat any like-for-like UK address lookup price
Send us your current quote or invoice and we'll come back the same working day with a better price — plus free migration and integration support.
- Beat any like-for-like UK quote, monthly or annual
- Free migration + hands-on integration support
- No setup fees, no lock-in, cancel any time
Ready to get started?
Add Royal Mail PAF-verified UK address lookup to your site in minutes — start free, no card required.
