Difference b/w Simple function call & do_action call

The main benefit with hooks ( such as add_action ) is that they allow you to add additional logic very easily based on priority. The only way to achieve the same thing with a standalone function is to edit the function directly. You wouldn’t want to do this in premium theme ( or core ) as any time there’s an update your function will be overwritten.

Take the following example which outputs a title into the <title> tag. First we register our hook and put the call into the header.php file in it’s respective spot.

/**
 * Custom Theme Title
 */
function theme_custom_title() {
    do_action( 'theme_custom_title' );
}

header.php HTML

<title><?php echo theme_custom_title(); ?></title>

Now that our custom hook is set up let’s discuss priorities, the 3rd parameter of add_action. Priorities allow us to run additional functions in order of priority in Ascending order, let’s register 3 hooks to our Custom Hook.

function custom_title_one() {
    echo "Hook One ";
}
add_action( 'theme_custom_title', 'custom_title_one', 10 );

function custom_title_two() {
    echo "Hook Two ";
}
add_action( 'theme_custom_title', 'custom_title_two', 20 );

function custom_title_three() {
    echo "Hook Three ";
}
add_action( 'theme_custom_title', 'custom_title_three', 1 );

If we run the above we’ll see the following output in the <title> tag:

Hook Three Hook One Hook Two

While it may seem trivial, this is fantastic for functions / hooks you do not want to actually overwrite. We could add these three hooks into a Child Theme and it will always run these hooks no matter how many times the Parent Theme updates. If the function takes parameters you could conditionally handle and manipulate the parameter and return different output. This is much more difficult to achieve as a stand alone function and the purpose is to allow developers to modify the main function without actually overwriting its core functionality.