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.

Get more useful WP tricks and snippets by subscribing to my mailclub.

2 Replies to “Random user agents for WordPress Remote Requests”

  1. Thanks! You used “user_agent_choser” instead of “random_user_agent” in the “remote_request” function

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.