A custom plugin lets you add features to WordPress without touching your theme. If you change themes later, your feature stays. That is why custom functionality belongs in a plugin.
The smallest possible plugin
Create a folder in wp-content/plugins, for example sd-notice, and add a PHP file with a plugin header. This example adds a [notice] shortcode:
<?php
/**
* Plugin Name: SD Notice Box
* Description: Adds a [notice] shortcode.
* Version: 1.0.0
* Author: Muhammad Saeed
* License: GPL-2.0-or-later
*/
defined( 'ABSPATH' ) || exit;
function sd_notice_shortcode( $atts, $content = '' ) {
$atts = shortcode_atts( array( 'type' => 'info' ), $atts, 'notice' );
return '<div class="sd-notice sd-' . esc_attr( $atts['type'] ) . '">' . esc_html( $content ) . '</div>';
}
add_shortcode( 'notice', 'sd_notice_shortcode' );
Activate it, then write [notice type="info"]Hello[/notice] in any post.
Security basics for every plugin
- Block direct access: start every file with
defined( 'ABSPATH' ) || exit;. - Escape output: use
esc_html,esc_attrandesc_urlwhen printing data. - Sanitize input: use functions such as
sanitize_text_fieldon anything a user sends. - Use nonces: protect forms and actions with
wp_nonce_fieldandwp_verify_nonce. - Check capabilities: use
current_user_canbefore any admin action. - Prefix everything: function, option and class names need a unique prefix.
When to build a custom plugin
Build one when you need a feature that no existing plugin does well: a custom booking form, an order calculator, an API integration or a special admin screen. A focused custom plugin is often lighter and safer than installing several general ones.
I build custom WordPress plugins for client projects. Tell me what you need and I will suggest the simplest solution.