Shortcodes with parameters
📖 Scenario: You are building a WordPress site and want to create a shortcode that shows a greeting message. The message should change based on a name you provide as a parameter.
🎯 Goal: Create a WordPress shortcode called [greet] that accepts a name parameter and displays a greeting like "Hello, [name]!".
📋 What You'll Learn
Create a function called
greet_shortcode that accepts attributes.Use
shortcode_atts to set a default name parameter to "Guest".Return a greeting string using the
name parameter.Register the shortcode
greet with the greet_shortcode function.💡 Why This Matters
🌍 Real World
Shortcodes let WordPress users add dynamic content easily inside posts or pages without coding each time.
💼 Career
Knowing how to create and customize shortcodes is useful for WordPress developers and site builders to extend site functionality.
Progress0 / 4 steps