Does anyone know a non-hacky way of getting the plugin directory path from within a theme’s functions.php?
I’ve used plugin_dir_path(FILE), but because its called in the theme’s functions.php it returns the path to that file. Not the plugins directory. I could string manipulate it and add the plugins path, but that feels nearly as bad as hardcoding the whole path.
I have got it working using:
require_once( ABSPATH .'/wp-content/plugins/ehu-events/event-widget.php' );
But I know that’s so oldschool and wrong and I’d probably be shunned from the wordpress community for using it!
Is there a standard wordpress function I can use for this?
Maybe what you’re looking for is :
See documentation
I believe this may be more reliable than depending upon the constants.
The reason I suspect it may be more reliable is that the
plugins_url
function considers both theWPMU_PLUGIN_URL
and theWP_PLUGIN_URL
constants and will also respect theplugins_url
filter.