WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

 |- 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)
    { /* ... */ });

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?

share|improve this question
What happens if you replace plugins_url() with plugin_dir_url()? – Chip Bennett Feb 10 '12 at 20:37
up vote 1 down vote accepted

You can try to override it by using the following in config.php and see if it works as it will update your database, doing so will make it unable to be changed in your admin (it will be greyed out).

define('WP_SITEURL', 'http://example.com/');

And some alternative definitions, http://codex.wordpress.org/Editing_wp-config.php#WordPress_address_.28URL.29

If that doesn't work, I would check your .htaccess.

share|improve this answer
Turns out I had a define('WP_CONTENT_URL', 'http://www.example.com/wp-content'); left over from an older install. Thanks! – sholsinger Feb 10 '12 at 21:04

The plugins_url() function builds a URL string based on the Site URL you have configured. Remember, WordPress URL and Site URL are two different things.

plugins_url() is merely a concatenation of:

  • get_option( 'site_url' )
  • /wp-content
  • The folder of the plugin

So if you're seeing a www in your site, it's because site_url is set to use a www.

share|improve this answer
This was not the case, as there was a constant in my wp-config.php that defined WP_CONTENT_URL as 'http://www.example.com/wp-content'. Thanks for your time and attention regardless. – sholsinger Feb 10 '12 at 21:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.