• Skip to main content

Victor Font Consulting Group, LLC

Strategic IT Solutions for Complex Organizations

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network

DRY Coding WordPress Actions and Filters

posted on December 14, 2016

Desert Lizard for DRY Coding WordPress Actions and Filters

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.

  • 22shares
  • Facebook14
  • Twitter0
  • Pinterest2
  • LinkedIn6
  • Print
  • SMS0

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

 
We only use analytical cookies on our website that allow us to recognize and count the number of visitors, but they do not identify you individually. They help us to improve the way our website works. By clicking Accept you, agree to cookies being used in accordance with our Cookie Policy.