Performance: Common filter hooks
This affects how quickly WordPress processes and modifies data during page load and user interactions.
<?php add_filter('the_content', function($content) { return $content . ' '; }); ?>
<?php add_filter('the_content', function($content) { for ($i=0; $i<1000; $i++) { $content .= ' '; } return $content; }); ?>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy filter with loops | N/A (server-side) | N/A | N/A | [X] Bad |
| Lightweight filter with simple string concat | N/A (server-side) | N/A | N/A | [OK] Good |
add_filter.add_filter with correct parameters. Others use wrong function names.add_filter('the_title', function($title) {
return strtoupper($title);
});
// Later WordPress calls apply_filters('the_title', 'Hello World');add_filter('the_content', 'modify_content');
function modify_content($content) {
echo strtoupper($content);
}Pass the test and this pattern moves unknown