You need a local WordPress installation and access to its files. This exercise creates a shortcode that displays a greeting with a supplied name.
Create the plugin file
Create wp-content/plugins/reza-hello/reza-hello.php. The Plugin Name header lets WordPress discover the plugin.
<?php
/**
* Plugin Name: Reza Hello
* Description: A small shortcode learning example.
* Version: 1.0.0
*/
if (!defined("ABSPATH")) { exit; }
function rn_hello_shortcode($atts) {
$atts = shortcode_atts(["name" => "friend"], $atts);
return "<p>Hello, " . esc_html($atts["name"]) . "!</p>";
}
add_shortcode("rn_hello", "rn_hello_shortcode");Activate and use it
Activate Reza Hello from the Plugins screen. Add a Shortcode block to a page with the text below. A shortcode callback should return its output so WordPress can place it correctly.
[rn_hello name="Reza"]Practice
Change the name and inspect the result. Remove the name attribute to see the default. esc_html escapes data for an HTML text context; it does not replace authorization checks or validation for other uses.
Check your understanding
Should a shortcode callback return its result or only echo it?
Return the result so WordPress can insert it in the correct place.