• Can someone tell me how to best reference the path to a plugin directory (to reference a CSS or js file for example)?

    OK… I already have the answer – I just wanted to check I was using the best method

    http://codex.wordpress.org/Function_Reference/plugin_basename

    This gives:

    $x = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
    
    // $x will equal "http://[url-path-to-plugins]/[myplugin]/"
    
     function writeCSS() {
      echo ( '<link rel="stylesheet" type="text/css" href="'. $x . 'myplugin.css">' );
    }
    add_action('wp_head', 'writeCSS');

    But at the end it also mentions:

    WP_PLUGIN_URL – the url of the plugins directory (usually inside wp-content)
    WP_PLUGIN_DIR – the server path to the plugins directory

    So, why bother with the above function – why not just use the constants?

    So… a little bit confused

    Any pointers would be appreciated

    Thanks

    Omar

Viewing 1 replies (of 1 total)
  • Thread Starter OM2

    (@om2)

    ok figured it out 🙂
    i didn’t read the code, they reference the constants within the code sample mentioned above
    reading too fast

Viewing 1 replies (of 1 total)

The topic ‘How to reference a file in the plugin directory’ is closed to new replies.