What is wordpress action and filter hook?

Hooks are WordPress function which we can applied to an action OR and filter

Developer to changed default wordpress functionality for plugins and theme files

Example of a hook

Function custom_excerpt( $output ) {
  if ( has_excerpt() && ! is_attachment() ) {
    $output .= wpb_continue_reading_link();
  }
  Return $output;
}
add_filter( 'get_the_excerpt', 'custom_excerpt' );

Above code is help to add continue link to expert

Filter hook is help to modify the current function ex. 'get_the_excerpt'  wordpress function

Here are some Filters Functions

  1. has_filter()
  2. doing_filter()
  3. add_filter()
  4. remove_filter()
function custometheme_enqueue_script() {
    wp_enqueue_script( 'my-mine-js', 'mine.js', false );
}
add_action( 'wp_enqueue_scripts', 'custometheme_enqueue_script' );

Above code help to add Custom JS in your theme file.

Action hook allow to execute custom function

Here are some Actions Functions

  1. has_action()
  2. do_action()
  3. add_action()
  4. remove_action()

Hopefully this article to be helpful 🙂

Blog Catagory : WORDPRESS