When developing any type of software, you always want to keep your runtime code to a minimum. Functions should only be loaded and run if its necessary to save on resources. This is especially important on the WordPress platform.
One of the fun parts of programming is finding clever ways to do things. There’s always more than one way to peel a potato in software development. When using Array.filter() to test if an element exists or not in an array, one can use a variety of different ways to accomplish the same goal thanks mostly, to “truthiness.”
WordPress hooks are functions that allow you to manipulate the functions of other parts of the site. They’re straightforward to understand and use; but, they can be a little confusing in different contexts if you want to use them outside of a simple global function call. This article is meant to help by outlining all the ways you can assign functions to hooks as well as the advantages and disadvantages of each method.