I want to add the Max Mega Menu plugin into my theme for a project.

What i've done:

  • copy and paste plugin folder into my theme
  • include megamenu.php file into my theme function.php file

Needed to work:

  • include with theme
  • active when theme active

So, how can I include this plugin and activate it when my theme is activated?


If you include a plugin directly inside a theme then it will be rejected by both the WordPress.org theme directory and ThemeForest.

You should use TGMPA for including plugins with themes: http://tgmpluginactivation.com/

Further reading: http://code.tutsplus.com/tutorials/using-the-tgm-plugin-activation-library-in-your-themes--cms-20901

Using TGMPA means the plugin remains a plugin, WordPress loads it in the normal 'plugin' way, and users will get plugin updates as they're released.

  • thanks for sharing those links it's very helpful. Another thing is this is a custom project for my client. – shamim khan Aug 31 '16 at 10:58

You cannot simply include a plugin in your theme by calling it from your functions.php. The reason is that if the user already has the same plugin installed, this will lead to a fatal error.

Also, you shouldn't move parts of the plugin to your theme, because you don't know how the plugin works internally. It might be looking for a file that isn't there and throw an error.

So, the right way to do this is have the complete plugin in a subdirectory of your theme and call it only after you have checked whether it hasn't already be loaded. This can be done by checking the existence of a certain function or class that you know is available in the plugin. Sample code:

add_action('after_setup_theme', 'wpse237683_load_plugin');

function wpse237683_load_plugin() {
    if (!class_exists('wpse237683')) {
        include_once (get_template_directory() . 'plugins/wpse237683/wpse237683.php');

There are still various pitfalls. You can try solving these yourself or use a PHP library like TGMPA that will manage this for you.

  • Prefer get_template_directory() to TEMPLATEPATH. – bravokeyl Aug 31 '16 at 8:50
  • @bravokeyl True. Fixed. – cjbj Aug 31 '16 at 8:52
  • thanks for your tips. I think TGMPA is the best solution for me. – shamim khan Aug 31 '16 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.