The filter changes the title by converting it to uppercase using strtoupper.
Step 2: Apply the filter to the input string
When WordPress applies the filter to 'Hello World', it returns 'HELLO WORLD'.
Final Answer:
"HELLO WORLD" -> Option A
Quick Check:
Filter changes title to uppercase = C [OK]
Hint: Filter returns modified data, here uppercase string [OK]
Common Mistakes:
Assuming original string is unchanged
Confusing add_filter with add_action
Expecting lowercase instead of uppercase
4. Identify the error in this filter hook code:
add_filter('the_content', 'modify_content');
function modify_content($content) {
echo strtoupper($content);
}
medium
A. The filter name 'the_content' is incorrect
B. The function name must start with 'filter_'
C. The function should return the modified content, not echo it
D. add_filter requires three parameters
Solution
Step 1: Review the filter function behavior
Filter functions must return the modified data, not output it directly.
Step 2: Check the code for return vs echo
The function uses echo instead of return, so WordPress won't get the modified content.
Final Answer:
The function should return the modified content, not echo it -> Option C
Quick Check:
Filter functions must return data = B [OK]
Hint: Filter functions must return modified data, not print it [OK]
Common Mistakes:
Using echo instead of return in filter functions
Thinking filter names are arbitrary
Believing add_filter always needs three parameters
5. You want to add a filter that appends " - Powered by WordPress" to every post title but only if the title is not empty. Which code correctly implements this?
hard
A. add_filter('the_title', function($title) {
if ($title !== '') {
return $title . ' - Powered by WordPress';
}
return $title;
});
B. add_filter('the_title', function($title) {
if ($title) {
echo $title . ' - Powered by WordPress';
}
});
C. add_filter('the_title', function() {
return ' - Powered by WordPress';
});
D. add_filter('the_title', function($title) {
return $title . ' - Powered by WordPress';
});
Solution
Step 1: Check the condition for empty title
add_filter('the_title', function($title) {
if ($title !== '') {
return $title . ' - Powered by WordPress';
}
return $title;
}); checks if the title is not empty before appending the text, which matches the requirement.
Step 2: Verify the function returns the modified title
add_filter('the_title', function($title) {
if ($title !== '') {
return $title . ' - Powered by WordPress';
}
return $title;
}); returns the modified title correctly; add_filter('the_title', function($title) {
if ($title) {
echo $title . ' - Powered by WordPress';
}
}); uses echo which is wrong, C ignores the original title, D appends text even if title is empty.
Final Answer:
code with condition and return -> Option A
Quick Check:
Check empty title and return modified string = A [OK]
Hint: Return modified title only if not empty, use return not echo [OK]
Common Mistakes:
Using echo instead of return
Not checking if title is empty
Replacing title instead of appending
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.