It’s highly recommended not to include the plugin directly inside a WordPress theme or plugin. Including the plugin inside a theme or plugin can lead to potential problems such as:
- The plugin is being already installed on website
- Maybe the plugin is included in another plugin. In this case, we can’t be sure which version of the plugin is used and that can break the website (see this discussion)
To avoid these problems, I recommend using TGM Activation Class to tell users that your theme needs the Meta Box plugin to run properly. This class is easy to use and configure (just follow the instruction at its homepage – simply copy and paste with small changes such as plugin name and slug).
This is the sample code that I use in NOISE theme:
To see more examples of using Meta Box inside a WordPress theme using TGM Activation Class, please take a look at these premium themes.
If you already included the Meta Box plugin inside your themes/plugins or you purchased a theme/plugin which already did that), then please follow these steps:
define( 'RWMB_DIR', get_template_directory() . '/meta-box/' ); define( 'RWMB_URL', get_template_directory_uri() . '/meta-box/' );
Here we assume that the plugin folder
meta-box is put in theme folder. If you put the plugin inside a theme’s subfolder (
lib for example), then you should define variables like this:
define( 'RWMB_DIR', get_template_directory() . '/lib/meta-box/' ); define( 'RWMB_URL', get_template_directory_uri() . '/lib/meta-box/' );
Note: This method is not recommended. Please use TGM Activation Class (above) if you have a choice.
Simply do this:
require_once RWMB_DIR . 'meta-box.php';