Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a filter hook that modifies the content.
Wordpress
<?php add_filter('the_content', [1]); function modify_content($content) { return $content . ' - Modified'; } ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function name without quotes.
Using a function name that does not exist.
✗ Incorrect
The function name 'modify_content' must be passed as a string to add_filter to hook it properly.
2fill in blank
mediumComplete the code to apply the filter and get the modified content.
Wordpress
<?php $content = 'Hello World'; $modified = apply_filters('the_content', [1]); echo $modified; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string literal instead of the variable.
Passing the output variable instead of the input.
✗ Incorrect
apply_filters needs the original content variable to pass through the filter hooks.
3fill in blank
hardFix the error in the filter hook registration by completing the code.
Wordpress
<?php add_filter('the_title', [1]); function change_title($title) { return strtoupper($title); } ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Including parentheses after the function name.
Passing the function name without quotes.
✗ Incorrect
The function name must be passed as a string without parentheses to add_filter.
4fill in blank
hardFill both blanks to create a filter hook that adds a suffix to the excerpt.
Wordpress
<?php add_filter([1], [2]); function add_suffix($excerpt) { return $excerpt . '... Read more'; } ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up filter tag and function name.
Using incorrect filter tag names.
✗ Incorrect
The filter name is 'the_excerpt' and the function hooked is 'add_suffix'.
5fill in blank
hardFill all three blanks to create a filter hook that changes the author name to uppercase.
Wordpress
<?php add_filter([1], [2]); function [3]($author) { return strtoupper($author); } ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not matching the function name in all places.
Passing function name without quotes in add_filter.
✗ Incorrect
The filter tag is 'the_author', the function name is 'uppercase_author' passed as string, and the function is named uppercase_author.