Reputation: 2839
My WP site works on both www and non-www, but I have a form that makes a call to admin-ajax.php and when I'm on www I get a CORS error.
The form is using <?php echo admin_url('admin-ajax.php'); ?>
to get the admin ajax url but it always gets it without www so I get this error:
Is there a way to get the admin url with www or without www depending on whether the user is on www or non www or can I change admin-ajax to accept for www or non www? or do I just need to change the js to construct the admin url without using the WP php functions?
Upvotes: 0
Views: 728
Reputation: 356
Check the $_SERVER['SERVER_NAME']
variable and compare it to admin_url. Then add or delete the www subdomain using this value str_replace function to avoid getting the error where the function is running.
Upvotes: 1