Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define the main plugin file header.
Wordpress
<?php
/*
Plugin Name: [1]
*/
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using function names instead of plugin name in header
Omitting the plugin header comment block
✗ Incorrect
The plugin header must include the Plugin Name to identify the plugin.
2fill in blank
mediumComplete the code to enqueue a stylesheet in the plugin.
Wordpress
<?php
function my_plugin_styles() {
wp_enqueue_style('[1]', plugin_dir_url(__FILE__) . 'css/style.css');
}
add_action('wp_enqueue_scripts', 'my_plugin_styles'); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the filename instead of a unique handle
Using incorrect function names
✗ Incorrect
The first argument of wp_enqueue_style is a unique handle for the stylesheet.
3fill in blank
hardFix the error in the plugin main file to prevent direct access.
Wordpress
<?php if (!defined('[1]')) { exit; } // Plugin code continues here
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect constants
Not preventing direct access
✗ Incorrect
Checking if ABSPATH is defined prevents direct access to the plugin file.
4fill in blank
hardFill both blanks to register a shortcode in the plugin.
Wordpress
<?php function [1]() { return 'Hello, World!'; } add_shortcode('[2]', '[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching function and shortcode names
Using invalid shortcode tags
✗ Incorrect
The function name and shortcode tag must match correctly to register the shortcode.
5fill in blank
hardFill both blanks to create a plugin activation hook.
Wordpress
<?php function [1]() { // Activation code here } register_activation_hook(__FILE__, '[1]'); add_action('[2]', '[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different function names in hook registration
Using wrong hook names
✗ Incorrect
The activation function name is used in both register_activation_hook and add_action with the correct hook.