Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using this function plugins_url().

But it always echoes main site url even in subsite.

So i'm getting ajax errors like Domains, protocols and ports must match.

Lets say my main domain name is and my subdomain is

Is there any function available that returns instead of



As of now i'm using like this.

home_url( '/' ).'wp-content/plugins/'.str_replace(basename(__FILE__),"",plugin_basename(__FILE__))

Here wp-content/plugins/ text hard coded.

So any other alternative method there?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

The plugins_url() function is designed to work in WordPress Multisite. Here is an example of its proper usage:

echo "<img src="' .plugins_url( 'images/wordpress.png' , __FILE__ ). '" > ';

If you are using this function in a file that is nested inside a subdirectory, you should use PHP's dirname() function:

echo "<img src="' .plugins_url( 'images/wordpress.png' , dirname(__FILE__) ). '" > ';
share|improve this answer

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.