Hello All, Happy New Year 🙂 .In this quick article I will show, how to allow external url/host in wordpress.Recently i was working with wordpress for getting data from external feed url.
So, When I tried to access data from same domain,it was working fine but when i tried to access data from other domain/host, I got following error:
1 2 3 | WP HTTP Error: A valid URL was not provided |
I googled to get solution for above error in wordpress and what does it mean. This error occur because by default external urls are disabled in wordpress for security reason.So you need to allow external host/domain explicitly using following line of code into your functions.php
file or your plugin’s main file:
1 2 3 4 5 6 7 8 | if ( $host == 'your-domain.com' ) $allow = true; return $allow; } |
Here,I have used http_request_host_is_external
filter which is used to check HTTP request is external or not.In condiiton pass your external domain you want to allow.
So that’s it for now from my side. Hope this article will be useful to someone.
Suggested Reading:
Post via e-mail in WordPress
Customize Contact Form 7 in WordPress
User Roles in WordPress
If you have any query or question,tell us in the comment section :). Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.