DRY in WordPress Templates
-
When displaying posts in your WordPress theme, you usually have the same chunk of code in multiple places throughout your theme, and it usually never changes.
For example, you typically have the same code in index.php, archive.php, search.php etc. and even the single.php page contains very similar code.That doesn’t make any sense at all. A better approach is to include that code in one file, and reference it from there: Don’t Repeat Yourself.
I cover this in this short screencast.
I realised how horrible WP theme code can be after using Ruby on Rails for a month. Rails encourages the DRY programming philosophy and I believe WordPress should take this direction also.
I’d love to hear the community’s opinion on this. Maybe we can revolutionise how templates are coded?
The topic ‘DRY in WordPress Templates’ is closed to new replies.