Random user agents for WordPress Remote Requests

wp_remote_get() and wp_remote_post() functions helps us to fetch data from external source: grabbing websites, getting data from public sources, API’s etc.

Sometimes using default headers causes suspect at external side. Too often requests can cause asking a captcha, or blocking your IP.

To escape from such problems we need to insert real visitor like user agents to our requests. And not only one, but randomly chosen ones.

Here is sample code for WordPress

wordpress remote requests

remote_request() function will return normal array which contains $response[‘headers’] and $response[‘body’] data.

Leave a Reply