0
0
Wordpressframework~10 mins

Functions.php role 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 custom function in functions.php.

Wordpress
<?php
function [1]() {
    // Custom code here
}
?>
Drag options to blanks, or click blank then click option'
Amy_custom_function
Bheader
Cfooter
Dstyle
Attempts:
3 left
💡 Hint
Common Mistakes
Using reserved WordPress function names
Leaving the function name blank
2fill in blank
medium

Complete the code to hook a function to WordPress initialization.

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

function custom_init_function() {
    // Initialization code
}
Drag options to blanks, or click blank then click option'
Aload_function
Binit_function
Ccustom_init_function
Dstart_function
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than defined
Missing quotes around the function name
3fill in blank
hard

Fix the error in the code to properly enqueue a stylesheet in functions.php.

Wordpress
function theme_styles() {
    wp_enqueue_style('[1]', get_template_directory_uri() . '/style.css');
}
add_action('wp_enqueue_scripts', 'theme_styles');
Drag options to blanks, or click blank then click option'
Astylesheet
Btheme-style
Cstyle
Dmain-style
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic handle names causing conflicts
Forgetting to hook the function to 'wp_enqueue_scripts'
4fill in blank
hard

Fill both blanks to create a shortcode that outputs 'Hello World'.

Wordpress
function [1]() {
    return '[2]';
}
add_shortcode('hello', '[1]');
Drag options to blanks, or click blank then click option'
Ahello_world
BHello World
Cgreeting
DHi there
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching function names in add_shortcode
Returning incorrect or empty strings
5fill in blank
hard

Fill all three blanks to register a custom widget in functions.php.

Wordpress
function [1]() {
    register_widget('[2]');
}
add_action('[3]', '[1]');
Drag options to blanks, or click blank then click option'
Aregister_custom_widget
BCustom_Widget_Class
Cwidgets_init
Dinit
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong hook names like 'init' instead of 'widgets_init'
Mismatching function names in add_action