0
0
Wordpressframework~10 mins

Shortcodes with parameters in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to register a shortcode named 'greet'.

Wordpress
add_shortcode('[1]', 'greet_function');
Drag options to blanks, or click blank then click option'
Ashortcode
Bhello
Cwelcome
Dgreet
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name instead of the shortcode tag.
Using uppercase letters in the shortcode name.
2fill in blank
medium

Complete 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'
Aname
Btitle
Cperson
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different key than defined in shortcode_atts.
Forgetting to use quotes around the key.
3fill in blank
hard

Fix 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'
A$atts.name
B$atts->name
C$atts['name']
D$atts[name]
Attempts:
3 left
💡 Hint
Common Mistakes
Using object property syntax on an array.
Omitting quotes around the key.
4fill in blank
hard

Fill 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'
Aname
Buser
Cguest
Dvisitor
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys for default and access.
Using keys not defined in shortcode_atts.
5fill in blank
hard

Fill 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'
Aname
Btime
Dday
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up keys between default and access.
Using inconsistent parameter names.