WordPress.org

Ready to get started?Download WordPress

Forums

How to get a plugin path (directory) (5 posts)

  1. Gustavo Straube
    Member
    Posted 5 years ago #

    Hi all!

    I want to get the plugin directory for a specific plugin, how can I do this? The target is show a image hosted on my plugin directory inside a widget. Something like this:

    function my_plugin_widget() {
    ...
    $dir = fn_to_get_plugin_directory();
    echo "<img src='{$dir}/img.gif' />";
    ...
    }

    Is it possible? Anyone have another suggestion for how can I do this?

    Thanks!

  2. Dagon Design
    Member
    Posted 5 years ago #

    Here is one method I use sometimes. To replace the line you have above, try this:

    $dir = ABSPATH . 'wp-content/plugins/plugin-folder/img.gif'

  3. Gustavo Straube
    Member
    Posted 4 years ago #

    I've tried to use the ABSPATH constant, but it doesn't work. The value contained in this constant is the full path from my HD root directory (C:\...). There is some constant or var that contains the absolute path from Apache's root directory (http://localhost/...) or something like this?

    Thank you!

  4. Gustavo Straube
    Member
    Posted 4 years ago #

    I got this working now!

    I'm using bloginfo('wpurl') function followed by the plugin directory path (/wp-content/plugins/...).

    Any better way to do this?

  5. WP Jan
    Member
    Posted 4 years ago #

    You could also use the "Plugin basename" ( http://codex.wordpress.org/Function_Reference/plugin_basename )

Topic Closed

This topic has been closed to new replies.

About this Topic