Learn WORDPRESS-PHP-PLUGINS with Real Code Examples
Updated Nov 26, 2025
Code Sample Descriptions
1
Hello World WordPress Plugin
<?php
/*
Plugin Name: Hello World Plugin
Description: A simple plugin to display Hello World in the footer.
Version: 1.0
Author: Your Name
*/
add_action('wp_footer', 'hello_world_plugin');
function hello_world_plugin() {
echo '<p style="text-align:center;">Hello, World! from my first plugin</p>';
}
A minimal WordPress plugin that outputs 'Hello, World!' in the site footer.
2
Simple Admin Notice Plugin
<?php
/*
Plugin Name: Admin Notice Plugin
Description: Shows an admin notice in WordPress dashboard.
Version: 1.0
Author: Your Name
*/
add_action('admin_notices', 'custom_admin_notice');
function custom_admin_notice() {
echo '<div class="notice notice-success is-dismissible"><p>Hello, Admin!</p></div>';
}
Displays a custom admin notice in the WordPress dashboard.
3
Shortcode Example Plugin
<?php
/*
Plugin Name: Shortcode Example
Description: Adds a [hello_world] shortcode.
Version: 1.0
Author: Your Name
*/
add_shortcode('hello_world', 'hello_world_shortcode');
function hello_world_shortcode() {
return '<p>Hello, World! via shortcode</p>';
}
Adds a simple shortcode [hello_world] to display a message anywhere on the site.
4
Custom Footer Text Plugin
<?php
/*
Plugin Name: Custom Footer Text
Description: Replace footer text.
Version: 1.0
Author: Your Name
*/
add_filter('admin_footer_text', 'custom_footer_text');
function custom_footer_text() {
return 'Custom footer message here';
}
Replaces the default footer text with custom text.
5
Enqueue Custom Script Plugin
<?php
/*
Plugin Name: Custom Script Plugin
Description: Enqueues a custom JS script.
Version: 1.0
Author: Your Name
*/
add_action('wp_enqueue_scripts', 'enqueue_custom_script');
function enqueue_custom_script() {
wp_enqueue_script('custom-script', plugin_dir_url(__FILE__) . 'js/custom.js', array('jquery'), '1.0', true);
}
Adds a custom JavaScript file to the frontend of the site.
6
Custom Post Type Plugin
<?php
/*
Plugin Name: Custom Post Type Plugin
Description: Adds a 'Book' post type.
Version: 1.0
Author: Your Name
*/
add_action('init', 'register_book_post_type');
function register_book_post_type() {
register_post_type('book', array(
'labels' => array('name' => 'Books'),
'public' => true,
'supports' => array('title', 'editor', 'thumbnail')
));
}
Registers a custom post type called 'Book'.
7
Widget Example Plugin
<?php
/*
Plugin Name: Widget Example
Description: Adds a custom widget.
Version: 1.0
Author: Your Name
*/
class Hello_Widget extends WP_Widget {
function __construct() {
parent::__construct('hello_widget', 'Hello Widget');
}
public function widget($args, $instance) {
echo $args['before_widget'] . '<p>Hello, Widget!</p>' . $args['after_widget']
}
}
add_action('widgets_init', function(){ register_widget('Hello_Widget'); });
Adds a custom widget displaying a simple message.
8
Custom Admin Menu Plugin
<?php
/*
Plugin Name: Admin Menu Plugin
Description: Adds a custom admin menu.
Version: 1.0
Author: Your Name
*/
add_action('admin_menu', 'custom_admin_menu');
function custom_admin_menu() {
add_menu_page('My Plugin Page', 'My Plugin', 'manage_options', 'my-plugin', 'my_plugin_page');
}
function my_plugin_page() {
echo '<h1>Welcome to My Plugin</h1>'
}
Adds a custom menu item in the WordPress admin dashboard.
9
Custom REST API Endpoint Plugin
<?php
/*
Plugin Name: REST API Example
Description: Adds a custom REST endpoint.
Version: 1.0
Author: Your Name
*/
add_action('rest_api_init', function () {
register_rest_route('myplugin/v1', '/data', array(
'methods' => 'GET',
'callback' => 'myplugin_get_data'
));
});
function myplugin_get_data() {
return array('message' => 'Hello, REST API!')
}
Adds a custom REST API endpoint that returns JSON data.