Include Meta Box Plugin In Themes/Plugins

Using TGM Activation Class

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 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 makes website broken (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 – it’s simply copy and paste with small changes such as plugin name and slug).

This is the sample code that I use in Glamo theme:

To see more examples of using Meta Box inside a WordPress theme using TGM Activation Class, please take a look at my premium themes.

Include Meta Box directly

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:

Defining variables for Meta Box plugin:

define( 'RWMB_DIR', trailingslashit( get_template_directory() ) );
define( 'RWMB_URL', trailingslashit( get_template_directory_uri() ) );

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', trailingslashit( get_template_directory() ) . 'lib/' );
define( 'RWMB_URL', trailingslashit( get_template_directory() ) . 'lib/' );

Load the plugin’s main file

Simply do this:

require_once RWMB_DIR . 'meta-box.php';