I'm working on a plugin which we'll call "my-plugin" for the purposes of this question. The my-plugin directory looks like this:
my-plugin/
|- image.jpg
|- script.js
|- script.php
|- plugin.php
|- ajax.php
In script.php I have a section of code that specifies some JS. In it, I need a URL for ajax.php. e.g.:
<script type="text/javascript">
foo = jQuery.getJSON("<?= plugins_url('ajax.php', __FILE__); ?>", function (data)
{ /* ... */ });
</script>
My wordpress domain is configured with a subdomain-less base url e.g.: http://example.com/ however the URL returned from plugins_url
is: http://www.example.com/wp-content/plugins/my-plugin/ajax.php. Unfortunately this has the side effect of preventing the script from being loaded as jQuery's getJSON is consistently "canceling" the request when the HTTP 301 response is returned for the malformed address.
Why is plugins_url
(in WordPress 3.3.1) returning a URL with 'www' when WordPress's 'Site Address' setting doesn't have it?
plugins_url()
withplugin_dir_url()
?