Create plugin and admin panel menu with add_menu_page
First lesson, about which I want to talk will be basic. To start creating your own plugin, you just need to create a file in the folder wp-content/plugins/.
Let's name the file my-wp-plugin.php.
Let's add basic data to the plugin in the form of comments. These comments will be used by WordPress for future plugins..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php /** * @package Package name * @version 1.0 */ /* Plugin Name: My first wordpress plugin Plugin URI: https://wp-admin.com.ua Description: спасибо сайту wp-admin.com.ua, он научит меня делать плагины ) Armstrong: My Plugin. Author: Name Author Version: 1.0 Author URI: https://wp-admin.com.ua */ ?> |
I don't think it's worth describing each item., everything seems to be clear from the example. After creating a file from the plugin, you can activate it in the admin panel. But while the plugin does nothing.
The next step is programming the base plugin. And here we will paste the code, which will add an admin menu item.
Add the code of the created plugin:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?php /** * @package Package name * @version 1.0 */ /* Plugin Name: My first wordpress plugin Plugin URI: https://wp-admin.com.ua Description: спасибо сайту wp-admin.com.ua, он научит меня делать плагины ) Armstrong: My Plugin. Author: Name Author Version: 1.0 Author URI: https://wp-admin.com.ua */ add_action('admin_menu', 'create_custom_panel'); function create_custom_panel() { add_menu_page('menu page', 'Custom panel', 'manage_options', 'custom-panel', 'custom_panel'); } function custom_panel(){ echo '<div class="wrap"><div id="icon-options-general" class="icon32"> <br> </div> <h2>Custom panel</h2></div>'; } ?> |
Function add_action() calls a function, that fires before the site loads. Function add_menu_page() adds our menu. In general, everything is so simple. You can read more about the add_menu_page function in code at wordpress.org.
Be sure to read about how to make an icon for a new item., it helps to earn customer loyalty.
I have done everything described and it works great..
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.
Another good lesson in addition to this.
http://wp-admin.com.ua/sozdanie-menyu-s-podmenyu-dlya-plaginov-wordpreess/