It was built in PHP and can handle everything from blogging to commercial websites. In this article, I’ll show you how to make a WordPress plugin that adds a menu item to the admin console and creates a page for it. In fact, WordPress is used for both our blog and our website. One of the most widely used content management systems on the internet is WordPress.
Let’s get started with a simple plugin that says “Hello World!” on every page.
For it to be listed in the plugin subdirectory, it must at the very least have “Plugin Name” in the header. The header comment is used by WordPress to recognize that this is a plugin; it is only required for the plugin’s point of entry (other php files are called using include/require_once). To save the file, make sure it’s in the wp-content/plugins” subfolder of your WordPress installation. I recommend putting it in a subdirectory there so you can organize your plugin.
Go to the wordpress admin panel and select the “Plugins” menu option to enable the plugin. Locate and activate the new plugin.
“Hello world!” will now appear at the top left of every page of the website.
It’s not very useful, but it gives you an idea of how WordPress plugins work. This means we’ll need to limit the time our plugin is active. WordPress treats plugins in such a way that they are as pluggable as possible. When a plugin is activated, WordPress runs the plugin’s main php file.
Creating an Admin Panel from Scratch
This is useful for allowing a WordPress site’s administrator to configure your plugin. We can move on to creating a proper plugin that does something useful now that we know how to get a plugin recognized by WordPress. A good place to start would be to add a sidebar menu item that allows us to create a page in the admin console.
We create a menu item in the admin panel that takes us to a page that says “Hello World!” using the following code: When WordPress loads a page, it performs a series of actions, which we can access using the add_action function. To do so, we’ll need to hook into the action that loads the admin menu.
Let’s take a look at the different functions:
‘admin_menu’, ‘test_plugin_setup_menu’; add_action(‘admin_menu’, ‘test_plugin_setup_menu’);
We hook into the point where the admin panel’s menu bar begins to load and tell WordPress that we want to run the test_plugin_setup_menu function, which is a few lines below.
‘Test Plugin Page’, ‘Test Plugin’, ‘manage_options’, ‘test-plugin’, ‘test_init’ ); add_menu_page( ‘Test Plugin’, ‘
The second parameter is the label for our admin panel, which is ‘Test Plugin’. We simply write “Hello World!” in this case. We’ll put the menu page and the menu item entry here. The third parameter limits access to certain users with specific capabilities, limiting who can see the option. The title of our options page is ‘Test Plugin Page’, which is the first option. The slug used to identify the menu is ‘test-plugin’. When the option is selected, the final parameter ‘test_init’ is the name of the function we want to call; this allows us to add code to output HTML to our page.
Now that we’ve set up our options page, we’ll be able to experiment with some more WordPress features.
I’ll show you how to use a Web Service with your plugin next time.
I recommend checking out their official Codex for more information on creating plugins for WordPress, which is very well documented.
Learn how to use JPedal, our PDF viewer.
So far, the tutorial has been fantastic!
Is it possible to create a menu page that looks exactly like Posts but displays posts from a specific category, complete with all of its functionality?
We didn’t test this particular feature, but it should be possible to add. We released the code as a starting point for people to play around with.
thank you, sir
Thank you for the informative article.
Thank you so much for your kindness, my friend.
Guys, can you tell me what test_plug-in is in this?
Our admin panel is dubbed ‘Test Plugin.’ I’m not sure if I understand what you’re asking.
Thank you, beacoup. Thank you very much, Simon. Following your advice, I created my first WordPress plugin.
Thank you for writing this article. This is a very nice and useful custom plugin.
How can I separate the plugin and its administration from the rest of the php file? The admin will only appear if I combine all of the codes into a single php file.
Thank You for a Nice Post…!
Very nice!! Thank you so much for this blog.
Thank you for providing such a simple guide. I’ve only recently begun learning about WordPress plugins, so it’s fantastic that I came across your site.
Very nice!! ……many thanks for this blog………………
,,,,,,,,,,,,,,,,,,,,,, ,,,,,,,,,,,,,,,,,, persian language:
Thank you so much.
Thank you so much for making this available.
How do I make it more functional…? Is there another article that will help me understand plugins better?
We also published https://eurofreecode.com/2014/07/creating-wordpress-plugin-part-2-uploading-media-linking-web-service/ and https://eurofreecode.com/2014/07/creating-wordpress-plugin-part-3-adding-shortcodes/. Amit is a writer.
I hope you find both of them helpful.
I’m excited to read more articles in the future. Thank you for writing such an informative article. Continue to write!!! Thank you for sharing this information.
Thank you very much! This made it a lot easier to get started!
Thank you; it’s helpful.
Is there a way to call a function directly without using add_menu_page(), so that when the page loads, it displays a page function that you specify?
Thanks; it’s very useful; however, please include a submenu page as well.
Please accept my apologies for my poor English; I’m French… I tried to include a php file; it works with html, but the page doesn’t load with php. Any ideas? Thank you, and have a pleasant day.
It has a form, so I made a custom table to store the data from the form. How do I connect that form to a custom table? Using the plugin, I’ve created an admin menu.
plug_form.php: This file contains a simple html form with two text fields, one radio button, and one checkbox. admin_menu.php: contains plugin code as well as a form file to be used by the plugin (require fxn) and code for a custom table2). I’ve got two files: 1st
Thank you so much; this has been extremely beneficial.