Better naming for WordPress hooks

Next time you're out there writing some code for a custom WordPress theme or plugin, try thinking about adding colons or dots to your hook names. It makes it much more readable and easier to understand the separation between components and the function of the hook.

Filter:

# before
apply_filter('jwk_podcasts_default_url');
# after
apply_filter('jwk:podcasts:default_url');

Action:

# before
do_action('jwk_podcasts_rest_api_init');
# after
do_action('jwk:podcasts:rest_api:init');

It's really fun and makes keeping track of what your hooks really do a little easier. Have fun!

Josh Friend

Full-Stack Software Developer at Ramsey Solutions. I build mostly using Ruby on Rails, React, Laravel, and Magnolia CMS. I always wanted to be an inventor when I grew up, so now I enjoy providing simple, intuitive solutions to complex problems.

Nashville, Tennessee

Subscribe to joshwhatk

Get the latest posts delivered right to your inbox.