1

So i'm working on a plugin where I assign a default avatar to anyone that comments. The line i'm stuck on contains a theme directory reference but I want to reference the image in the plugin directory instead. Thanks in advance!

$new_avatar_url = get_bloginfo( 'plugin_directory' ) . '/avatar-1.jpg';
2

Try plugin_dir_url():

$new_avatar_url = plugin_dir_url( __FILE__ ) . '/avatar-1.jpg';
  • 1
    Note that the file where you call this from must be in the root directory of the plugin for this to work. – cjbj Sep 4 '16 at 15:07
  • Perfect, this is exactly what I was looking for! – Daire Sep 4 '16 at 21:06
0

You can use plugin_dir_path() (link to doc):

$dir = plugin_dir_path( __FILE__ ); // returns "/var/www/wp/wp-content/plugins/my-plugin/"

Or, if you only need the path inside your plugin, plugin_basename() is your friend (link to doc):

$dir = plugin_basename( __FILE__ ); // returns "my-plugin/my-plugin.php"
  • 1
    Note that the file where you call this from must be in the root directory of the plugin for this to work. – cjbj Sep 4 '16 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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