Complete the code to add a custom function in functions.php.
<?php
function [1]() {
// Custom code here
}
?>The functions.php file is used to add custom PHP functions like my_custom_function to your WordPress theme.
Complete the code to hook a function to WordPress initialization.
add_action('init', '[1]'); function custom_init_function() { // Initialization code }
The add_action function connects your custom function to the WordPress 'init' event. The function name must match exactly.
Fix the error in the code to properly enqueue a stylesheet in functions.php.
function theme_styles() {
wp_enqueue_style('[1]', get_template_directory_uri() . '/style.css');
}
add_action('wp_enqueue_scripts', 'theme_styles');The handle name in wp_enqueue_style should be unique and descriptive, like 'theme-style'.
Fill both blanks to create a shortcode that outputs 'Hello World'.
function [1]() { return '[2]'; } add_shortcode('hello', '[1]');
The function name 'hello_world' is used to define the shortcode output, which returns the string 'Hello World'.
Fill all three blanks to register a custom widget in functions.php.
function [1]() { register_widget('[2]'); } add_action('[3]', '[1]');
The function 'register_custom_widget' registers the widget class 'Custom_Widget_Class' during the 'widgets_init' action.