0
0
Wordpressframework~10 mins

Filter 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 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'
A'change_content'
B'content_filter'
C'filter_content'
D'modify_content'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the function name without quotes.
Using a function name that does not exist.
2fill in blank
medium

Complete 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'
A$content
B'content'
C'Hello World'
D$modified
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string literal instead of the variable.
Passing the output variable instead of the input.
3fill in blank
hard

Fix 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'
A'change_title'
Bchange_title()
Cchange_title
D'changeTitle'
Attempts:
3 left
💡 Hint
Common Mistakes
Including parentheses after the function name.
Passing the function name without quotes.
4fill in blank
hard

Fill 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'
A'the_excerpt'
B'add_suffix'
C'excerpt_suffix'
D'suffix_function'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up filter tag and function name.
Using incorrect filter tag names.
5fill in blank
hard

Fill 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'
A'the_author'
B'uppercase_author'
Cuppercase_author
Attempts:
3 left
💡 Hint
Common Mistakes
Not matching the function name in all places.
Passing function name without quotes in add_filter.