0
0
Wordpressframework~30 mins

Creating shortcodes in Wordpress - Try It Yourself

Choose your learning style9 modes available
Creating Shortcodes in WordPress
📖 Scenario: You want to add a simple reusable message block inside your WordPress posts without typing the full message every time.Shortcodes let you do this by typing a small code snippet that WordPress replaces with your message.
🎯 Goal: Build a WordPress shortcode that outputs a friendly greeting message when used inside posts or pages.
📋 What You'll Learn
Create a function that returns a greeting message
Register a shortcode named greeting linked to the function
Use the shortcode inside content to display the message
💡 Why This Matters
🌍 Real World
Shortcodes let WordPress users add reusable content blocks easily without coding each time.
💼 Career
Knowing how to create and register shortcodes is useful for WordPress developers customizing themes and plugins.
Progress0 / 4 steps
1
Create the greeting function
Create a function called my_greeting_function that returns the string 'Hello, welcome to my site!'.
Wordpress
Need a hint?

Use function my_greeting_function() { return 'Hello, welcome to my site!'; }

2
Register the shortcode
Add a line to register the shortcode greeting using add_shortcode that links to the function my_greeting_function.
Wordpress
Need a hint?

Use add_shortcode('greeting', 'my_greeting_function'); to register the shortcode.

3
Use the shortcode in content
Write a comment showing how to use the shortcode [greeting] inside WordPress post content.
Wordpress
Need a hint?

Write a comment like // Use the shortcode [greeting] inside post content

4
Complete the plugin file
Add the PHP opening tag <?php at the top if missing and ensure the full code is ready to be saved as a plugin file.
Wordpress
Need a hint?

Make sure the file starts with <?php and includes the function and shortcode registration.