If you're not familiar with the concept of DRY coding, DRY is acronym that means Don't Repeat Yourself. But what does this really mean? Let's take a look at an example from the Genesis Framework. The following snippet is the code from the Executive Pro theme's archive-portfolio.php. This is a custom archive template for the Portfolio custom post type. I've taken the liberty of highlighting a few lines for clarity.
Notice how the WordPress remove_action function is called over and over again to remove Genesis actions? This can be done in a much simpler way, without repeating the function call over and over again. The advantage is that there is only one place in your code to go to when you need to look for or change something. This snippet is a refactoring of all of those remove_action calls:
The same can be done with add_filter or add_action is there you have more than one reason to call them in your code. It makes for easier to maintain, readable code.
Leave a Reply