Attaching icons to menu items has become a trend. WordPress theme developers need to build a functionality write into WordPress theme to provide users to choose icons for menu items. For themes which don’t support menu icons, users usually used plugins like Menu Icons to achieve this functionality.
Menu Icons in WordPress Themes
We can actually pack this plugin in our theme and install it automatically when the theme is installed by the user. Its completely legal to pack third party plugins into your theme if these plugins are open source plugins.
You can install Menu icons plugin automatically using TGM Plugin Activation Library.
First download class-tgm-plugin-activation.php file and put it inside the theme folder. And then put this code in your functions.php file
require_once dirname( __FILE__ ) . '/class-tgm-plugin-activation.php';
add_action( 'tgmpa_register', 'mytheme_require_plugins' );
function mytheme_require_plugins() {
$plugins = array( array(
'name' => 'Menu Icons',
'slug' => 'menu-icons',
'required' => true, // this plugin is recommended
'force_activation' => true, // this plugin is going to stay activated unless the user switches to another theme
'force_deactivation' => true, // deactivate this plugin when the user switches to another theme
) );
$config = array(
'id' => 'qnimate-tgmpa', // your unique TGMPA ID
'default_path' => get_stylesheet_directory() . '/lib/plugins/', // default absolute path
'menu' => 'qnimate-install-required-plugins', // menu slug
'has_notices' => true, // Show admin notices
'dismissable' => false, // the notices are NOT dismissable
'dismiss_msg' => 'I really, really need you to install these plugins, okay?', // this message will be output at top of nag
'is_automatic' => true, // automatically activate plugins after installation
'message' => '<!--Hey there.-->', // message to output right before the plugins table
'strings' => array() // The array of message strings that TGM Plugin Activation uses
);
tgmpa( $plugins, $config );
}
?>
Now whoever installs your theme will have the plugin installed and it will seem like the theme has this built in functionality.