WP_PLUGIN_DIR.'/pluginName/'
will give you the absolute path to the directory of the plugin.
EDIT After comment
Plugins are plugins, theme files are theme files. Lets not confuse the two.
You cannot copy a plugin in the theme directory – because stuff does not work like that.
After careful editing you can include the plugin as part of your themes options.
Lets make an example:
-
I want to include the hello dolly plugin in my theme. So I copy hello.php into my themes directory like so:
themes/mytheme/include/plugins/hello.php
. -
In order to load this file (“plugin” – but its not really a plugin anymore) I need to
require_once
thehello.php
file like so:define('mytheme_inc_path', TEMPLATEPATH . '/includes/'); define('mytheme_inc_url', get_template_directory_uri(). '/includes/'); require_once mytheme_inc_path. 'plugins/hello.php';
a. If I have a more complex “plugin” then the code will be like this:
require_once mytheme_inc_path. 'plugins/myplugin/myplugin.php'; // because the plugin deserves its own directory
Within the
myplugin.php
you will enqueue the required scripts and styles like so:function mytheme_plugin_scripts() { wp_enqueue_script('tiled-gallery', mytheme_inc_url . 'tiled-gallery/tiled-gallery.js', array('jquery') ); wp_enqueue_style('tiled-gallery', mytheme_inc_url . 'tiled-gallery/tiled-gallery.css', array(), '2012-09-21'); } add_action('wp_enqueue_scripts', 'mytheme_plugin_scripts');
Caution
- Be sure to remove unwanted ‘plugin’
hooks
(filter, activation/deactivation or otherwise). - Be sure to remove all other
actions
except those that you really require
Conclusion
If you did some research in script/style enqueue how-to’s you’d know that plugins (that are stored in wp-content/plugins
or wp-content/mu-plugins
use a bit different functions to retrieve absolute/relative path and uri. Like so: