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?
Use
plugin_dir_url( __FILE__ );
for the URL andplugin_dir_path( __FILE__ );
for the path.Pass the pluginâs main file to both functions to get similar results.
Besides that,
ADMIN_PATH
andADMIN_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.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-aa-style
is the element id make sure to define acss folder
and awp-aa-style.css
file inside your WordPress plugin’s main folderAdding 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.