List out hook in wordpress.

Hooks in WordPress are functions that allow developers to modify or add functionality to WordPress without changing the core files.

There are two main types of hooks:

A. Action Hooks

Action hooks are used to execute a function at a specific point in WordPress.

Common Action Hooks:

  1. init
  2. wp_loaded
  3. wp_head
  4. wp_footer
  5. admin_init
  6. admin_menu
  7. admin_enqueue_scripts
  8. wp_enqueue_scripts
  9. save_post
  10. publish_post
  11. login_init
  12. user_register
  13. comment_post
  14. widgets_init
  15. after_setup_theme

Example:

function my_function() {
    echo "Hello WordPress";
}

add_action('wp_footer', 'my_function');

B. Filter Hooks

Filter hooks are used to modify or change existing data before it is displayed or stored.

Common Filter Hooks:

  1. the_content
  2. the_title
  3. the_excerpt
  4. the_permalink
  5. the_author
  6. wp_title
  7. body_class
  8. post_class
  9. excerpt_length
  10. excerpt_more
  11. upload_mimes
  12. login_redirect
  13. comment_text
  14. widget_text
  15. document_title_parts

Example:

function change_title($title) {
    return $title . " - My Website";
}

add_filter('the_title', 'change_title');

Difference

Action HookFilter Hook
Performs an actionModifies data
Does not normally return a valueMust return the modified value
Uses add_action()Uses add_filter()
Example: wp_footerExample: the_content

In short:
Action = Do something
Filter = Change something

By admin