Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to register a shortcode named 'greet'.
Wordpress
add_shortcode('[1]', 'greet_function');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name instead of the shortcode tag.
Using uppercase letters in the shortcode name.
✗ Incorrect
The shortcode name must match the first argument in add_shortcode to register it correctly.
2fill in blank
mediumComplete the function to get the 'name' parameter from shortcode attributes.
Wordpress
function greet_function($atts) {
$atts = shortcode_atts(array('name' => 'Guest'), $atts);
return 'Hello, ' . $atts['[1]'] . '!';
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different key than defined in shortcode_atts.
Forgetting to use quotes around the key.
✗ Incorrect
The 'name' key is used to access the parameter passed in the shortcode attributes.
3fill in blank
hardFix the error in the shortcode function to correctly return the greeting.
Wordpress
function greet_function($atts) {
$atts = shortcode_atts(array('name' => 'Guest'), $atts);
return 'Hello, ' . [1] . '!';
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using object property syntax on an array.
Omitting quotes around the key.
✗ Incorrect
Shortcode attributes are arrays, so use square brackets with quotes to access values.
4fill in blank
hardFill both blanks to create a shortcode that returns a message with a default and user parameter.
Wordpress
function greet_function($atts) {
$atts = shortcode_atts(array('[1]' => 'Guest'), $atts);
return 'Welcome, ' . $atts['[2]'] . '!';
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys for default and access.
Using keys not defined in shortcode_atts.
✗ Incorrect
Both blanks must use 'name' to match the default attribute and the accessed key.
5fill in blank
hardFill all three blanks to create a shortcode that returns a custom message with parameters 'name' and 'time'.
Wordpress
function greet_function($atts) {
$atts = shortcode_atts(array('[1]' => 'Guest', '[2]' => 'day'), $atts);
return 'Good ' . $atts['[2]'] . ', ' . $atts['[3]'] . '!';
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up keys between default and access.
Using inconsistent parameter names.
✗ Incorrect
The first blank is the 'name' key, second is 'time', and third is 'name' to access the correct parameters.