0
0
Wordpressframework~10 mins

Action hooks 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 add a function to a WordPress action hook.

Wordpress
add_action('init', [1]);
Drag options to blanks, or click blank then click option'
A'my_custom_function'
Bmy_custom_function()
C'my_custom_function()'
Dmy_custom_function
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function name without quotes
Including parentheses in the function name string
2fill in blank
medium

Complete the code to define a function that runs on the 'wp_footer' action hook.

Wordpress
function [1]() {
    echo '<p>Footer text</p>';
}
add_action('wp_footer', '[1]');
Drag options to blanks, or click blank then click option'
Adisplay_footer
Bshow_footer
Cfooter_display
Dfooter_text
Attempts:
3 left
💡 Hint
Common Mistakes
Using different function names in definition and add_action
Forgetting to add the function to the action hook
3fill in blank
hard

Fix the error in the code to properly add a function to the 'admin_menu' action hook.

Wordpress
add_action('admin_menu', [1]);

function add_custom_menu() {
    add_menu_page('Custom Menu', 'Custom Menu', 'manage_options', 'custom-menu', 'custom_menu_callback');
}
Drag options to blanks, or click blank then click option'
Aadd_custom_menu
Badd_custom_menu()
C'add_custom_menu'
D'add_custom_menu()'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function call instead of the function name
Including parentheses inside the string
4fill in blank
hard

Fill both blanks to add a function with priority 15 and 2 accepted arguments to the 'save_post' action hook.

Wordpress
add_action('save_post', [1], [2], 2);
Drag options to blanks, or click blank then click option'
A'save_post_handler'
B10
C15
D'save_handler'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong priority number
Passing function name without quotes
5fill in blank
hard

Fill all three blanks to define a function hooked to 'the_content' filter that appends text to post content.

Wordpress
function [1]($content) {
    return $content . [2];
}
add_filter('the_content', [3]);
Drag options to blanks, or click blank then click option'
Aappend_text_to_content
B' - Thank you for reading!'
C'append_text_to_content'
D' - Read more on our site.'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching function names
Not using quotes around strings
Passing function call instead of function name