DEV Community

Cover image for What are hooks in WordPress?
Stackfindover
Stackfindover

Posted on

1

What are hooks in WordPress?

What are WordPress hooks?

WordPress hooks are a method for one piece of code to modify the behavior of another piece of code. They allow you to change how WordPress behaves without changing the core code itself. There are two types of hooks: actions and filters.

Types of WordPress hooks

There are two types of WordPress hooks: actions and filters.

Actions hook:
Actions hook allow you to insert additional code at specific points referred to as “hooks” throughout WordPress. For example, you can use an action to send an email or create a widget.

Filters hook:
Filters hooks allow you to modify existing code in WordPress. For example, you might use a filter to modify the content of a post before it is displayed or to change the post excerpt length of a WordPress site.

Here are some examples of action hooks:
wp_head: Executed within the <body> element of the page
wp_footer: Executed at the end of the page, before the </body> closing tag
publish_post: Executed when a post is published
delete_user: Executed when a user is deleted

And here are some examples of filter hooks:

the_title: Modifies the title of a post
the_content: Modifies the content of a post
wp_mail_from: Modifies the “from” address for emails sent by WordPress
excerpt_length: Modifies the length of post excerpts

There are many more action and filter hooks available in WordPress, and you can find a complete list in the WordPress Codex.

WordPress Hooks: A Complete Guide

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay