Ichsan's Ebook
  • Journal
  • Wordpress Development
    • Rest API
      • /posts
      • Adding Custom Endpoint
    • Hooks
      • Actions
        • Actions Run During an Admin Page Request
          • set_current_user
          • admin_menu
          • admin_footer
        • Template Actions
          • switch_theme
          • after_switch_theme
      • Filters
    • Functions
      • register_post_type
      • add_shortcode
      • add_dashboard_page
      • add_posts_page
      • add_management_page
      • add_menu_page
      • add_submenu_page
      • dbDelta
      • wpdb::get_results
      • wpdb::get_row
      • wpdb::delete
    • Properties
      • wpdb::insert_id
      • wpdb::last_error
      • wpdb::num_rows
      • wpdb::prefix
    • Hands On Tips & Trick
      • Include PHP file to add_menu_page()
    • Utils Methods
      • __FILE__
      • dirname()
      • __()
    • Conditional Tags
      • is_home
      • is_front_page
      • is_admin
      • is_single
      • is_singular
    • Roles and Capabilities
  • Template Hierarchy
Powered by GitBook
On this page
  1. Wordpress Development

Hooks

PreviousAdding Custom EndpointNextActions

Last updated 1 year ago

Hooks are a way for one piece of code to interact/modify another piece of code at specific, pre-defined spots. They make up the foundation for how plugins and themes interact with WordPress Core.

There are two types of hooks: and . To use either, you need to write a custom function known as a Callback, and then register it with a WordPress hook for a specific action or filter.

The main difference between an action and a filter can be summed up like this:

  • an action takes the info it receives, does something with it, and returns nothing. In other words: it acts on something and then exits, returning nothing back to the calling hook.

  • a filter takes the info it receives, modifies it somehow, and returns it. In other words: it filters something and passes it back to the hook for further use.

Said another way:

  • an action interrupts the code flow to do something, and then returns back to the normal flow without modifying anything;

  • a filter is used to modify something in a specific way so that the modification is then used by code later on.

Actions
Filters
Actions vs. Filters