It’s okay if I do not write add_action()

It is not always required technically but it is good practice to follow for multiple reasons:

  1. Code is more organized by keeping hook-related stuff together
  2. The more precise conditions when it runs – the better for performance
  3. It is easier to unhook function, that performs multiple add_, then unhook each add_ individually.
  4. The order of adding functions matters when not specifying priority.
  5. The child theme (if used) is processed before parent theme and it can lead to confusing stuff with hooks if add_ and remove_ are performed inline.

Of course in some specific examples (yours does fit) it does seem overly verbose to write out all of that just to manipulate single item on single hook.

Myself I use couple of my own (and somewhat messy functions) – add_filter_return() and add_action_with_arguments() to lower amount of wrapping when working with hooks.

tech