In WordPress, hooks are the building blocks for your themes and plugins and are vital for their functionality. Basically, their purpose is to allow developers to make their own custom code (and custom functionalities) to themes or plugins without changing any of the original WordPress files. There are two types of hooks that exist in WordPress: action hooks and filter hooks.
Action hooks are hooks that (this may be obvious) trigger an action. They can be inserted at certain points within your code to carry out actions by loading different custom functions from within your WordPress theme. To use an action hook, create a function or choose one of the functions in your functions.php file, and hook that function into your code by using the add_action() function. Here’s the syntax for using an action hook:
add_action( $hook, $function_to_add, $priority, $accepted_args );
Filter hooks are used to manipulate outputs or add particular content to certain loops to make an output appear after a trigger or after a certain type of content. For example, you can use filter hooks to ensure that a particular output (a link, a line of text, a footer) will appear after every instance of a particular type of content, like blog posts for example. This can be achieved by using the add_filter() function.
add_filter( $tag, $function_to_add, $priority, $accepted_args );