get plugin directory url

I am trying to use SMOF Options Framework in a plugin and i have this problem.
SMOOF use this constants to get theme directory url:

if( !defined('ADMIN_PATH') )
    define( 'ADMIN_PATH', get_template_directory() . '/admin/' );
if( !defined('ADMIN_DIR') )
    define( 'ADMIN_DIR', get_template_directory_uri() . '/admin/' );

But i want to use SMOF in a plugin, not in theme, how can i get the plugin directory url? What to put in order to get_template_directory() and get_template_directory_uri() to use it in a plugin?

Related posts

2 comments

  1. Use plugin_dir_url( __FILE__ ); for the URL and plugin_dir_path( __FILE__ ); for the path.

    Pass the plugin’s main file to both functions to get similar results.

    Besides that, ADMIN_PATH and ADMIN_DIR are really poor names for custom code. They might result in collisions with other code in the future. Try to use better names, something with a unique prefix.

  2. I have created a wordpress plugin that uses custom css/js code, in order to include these resources locally add a line like this one:

    wp_enqueue_style( 'wp-aa-style', plugin_dir_url( __FILE__ ) . 'css/wp-aa-style.css',false,'1.1','all');
    

    wp-aa-style is the element id make sure to define a css folder and a wp-aa-style.css file inside your WordPress plugin’s main folder

    Adding this answer hoping it will help someone willing to use plugin_dir_url( __FILE__ ) to make local resource calls (instead of static public URLs) for custom WordPress plugins.

Comments are closed.