What is the difference between add_action and add_filter in WordPress?



add_action is what you use to create a trigger “hook” – when something happens, do-something-else.

add_action ( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )


  • $tag
    (string) (Required) The name of the action to which the $function_to_add is hooked.
  • $function_to_add
    (callable) (Required) The name of the function you wish to be called.
  • $priority
    (int) (Optional) Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
    Default value: 10
  • $accepted_args
    (int) (Optional) The number of arguments the function accepts.
    Default value: 1

add_filter is used to “hook” data change/replace¬† – where there is [some-code], change it to some-other-expanded-code.
add_filter ( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )
Hook a function or method to a specific filter action.
WordPress offers filter hooks to allow plugins to modify various types of internal data at runtime.
A plugin can modify data by binding a callback to a filter hook. When the filter is later applied, each bound callback is run in order of priority, and given the opportunity to modify a value by returning a new value.