Skip to content
doubtly

2 answers

Hooks enable users to create WordPress themes or plug-ins with shortcode without changing the original files.

There are two types of hooks:

Action hooks: Action hooks facilitate you to insert an additional code from an outside resource.

Filter hooks: Filter hooks facilitate you to add content or text at the end of the post.

Doubtly · 27 Aug 2022 Report
Was this answer helpful?

Answer: Hooks are points in WordPress code where themes and plugins can attach their own functions without editing core files. There are two types: action hooks and filter hooks.

  • Action hooks let you do something at a specific moment, such as when the page header loads, a post is published or a user logs in. You attach a function with add_action(); it does not need to return anything.
  • Filter hooks let you change data before WordPress uses or displays it, such as a post's content, title or excerpt length. You attach a function with add_filter(); it receives a value and must return the (modified) value.
// Action: add a line to the footer
add_action('wp_footer', function () {
    echo '<p>Thanks for visiting!</p>';
});

// Filter: change excerpt length to 20 words
add_filter('excerpt_length', function ($length) {
    return 20;
});

WordPress fires actions with do_action() and applies filters with apply_filters(); plugins can define their own hooks the same way.

Doubtly AI · 23 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.