Introduction
Custom plugins let you add special features to your WordPress site that you can't get from ready-made plugins.
Custom plugins let you add special features to your WordPress site that you can't get from ready-made plugins.
<?php
/*
Plugin Name: Your Plugin Name
Description: What your plugin does
Version: 1.0
Author: Your Name
*/
// Your plugin code here
<?php /* Plugin Name: Hello World Plugin Description: Shows a hello message Version: 1.0 Author: You */ function hello_world() { echo 'Hello, world!'; } add_action('wp_footer', 'hello_world');
<?php /* Plugin Name: Custom Greeting Description: Displays a greeting based on time Version: 1.0 Author: You */ function time_based_greeting() { $hour = date('H'); if ($hour < 12) { echo 'Good morning!'; } else { echo 'Good afternoon!'; } } add_action('wp_footer', 'time_based_greeting');
This plugin adds a bright yellow notice at the top of every page to greet visitors.
<?php /* Plugin Name: Simple Notice Description: Adds a notice at the top of the site Version: 1.0 Author: You */ function add_site_notice() { echo '<div style="background:#ff0; padding:10px; text-align:center;">Welcome to our special site!</div>'; } add_action('wp_body_open', 'add_site_notice');
Always test your custom plugin on a staging site before using it live.
Keep your plugin code simple and focused on one task.
Use WordPress hooks like add_action and add_filter to connect your code.
Custom plugins let you add unique features tailored to your needs.
They help keep your site efficient by adding only what you want.
Writing a plugin starts with a simple PHP file and WordPress hooks.
<?php
/*
Plugin Name: Hello Plugin
*/
add_action('wp_footer', function() {
echo '<p>Hello from custom plugin!</p>';
});
?><?php
/*
Plugin Name: Faulty Plugin
*/
add_action('init', 'my_init_function');
function my_init_function() {
echo 'Init function called';
}
?>Pass the test and this pattern moves unknown