php-wordpressHow to create a WordPress plugin using PHP?
Creating a WordPress plugin using PHP is a relatively simple process. The following example code block will create a basic plugin that will display a message when activated:
<?php
/*
Plugin Name: My Plugin
Description: A basic plugin
*/
function my_plugin_function() {
echo 'My plugin is now active!';
}
register_activation_hook(__FILE__, 'my_plugin_function');
When the plugin is activated, the following output will be displayed:
My plugin is now active!
The code consists of the following parts:
-
Plugin Name and Description: This is the name and description of the plugin that will be displayed in the WordPress admin area.
-
my_plugin_function(): This is the function that will be executed when the plugin is activated.
-
register_activation_hook(): This is the function that will register the my_plugin_function() to be executed when the plugin is activated.
Helpful links
More of Php Wordpress
- How to get the current URL in WordPress using PHP?
- How to disable PHP warnings in WordPress?
- How to increase the upload limit in WordPress using PHP?
- How to check the PHP version in WordPress?
- How to run an SQL query in WordPress using PHP?
- How to create a snippet in WordPress using PHP?
- How to configure Nginx for WordPress?
- How to create a menu in WordPress using PHP?
- How to use get_header in WordPress using PHP?
- How to send an email using PHP in WordPress?
See more codes...