October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk9 min

WordPress Hooks Explained: Actions and Filters for Beginners

A practical beginner's guide to WordPress hooks, showing when to use actions or filters, how to register callbacks, control priority, create custom hooks, and remove callbacks safely.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WordPress hooks are predefined points where your code can connect to WordPress, a theme, or a plugin without editing its files. An action lets your callback perform a task when an event occurs; a filter lets your callback receive a value, change it, and return the revised value.

Once you know which type of hook you need, the basic pattern is simple: define a callback, register it with add_action() or add_filter(), then verify the hook’s priority and argument list in its reference.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a WordPress hook is and why it matters

A hook is an extension point built into WordPress, a theme, or a plugin. At that point, the original code either announces that something is happening or passes a value through a changeable pipeline. Other code can connect to that point with a callback function or method.

This design lets you change behavior from a plugin or a theme extension instead of modifying WordPress core files. Core edits are fragile: an update can overwrite them, and the change becomes difficult to disable or move. A hook keeps your customization separate and gives other components a predictable place to integrate.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

WordPress has two hook contracts:

  • Actions signal an event or execution point. Your callback does work there, such as printing markup, saving data, sending a notification, or triggering another process. The return value from an action callback is not used as replacement data.
  • Filters pass a value through your callback. Your function receives that value, optionally receives additional arguments, changes it, and must return the result for the next callback or the calling code.

The hook name is a string such as wp_footer or the_title. The name alone does not tell you the complete contract: the hook reference determines whether it is an action or filter, when it fires, which arguments it supplies, and what those arguments contain.

Actions and filters compared

Question Action Filter
Primary purpose Perform work at a defined point Transform a value during execution
Callback return value Not used by the action hook Required; returned value continues through the filter chain
Typical output Output, persistence, notifications, or another task A revised title, text string, setting, or other passed value
Side effects Expected when the task requires them Keep the callback focused on the value; avoid direct output or unrelated global-state changes
Registration function add_action() add_filter()

Use an action when the requirement sounds like “do this when WordPress reaches this point.” Use a filter when it sounds like “change this value before it is used or displayed.” Choosing the wrong contract is a common reason for code that appears to run but has no effect.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Register your first action

An action callback can be a named function or a method. The callback should have a unique prefix so it does not collide with another plugin or theme.

Basic action example

function wporg_show_message() {
    echo '<p>Hello from an action.</p>';
}
add_action( 'wp_footer', 'wporg_show_message' );

When WordPress fires wp_footer, it calls wporg_show_message(), which prints a paragraph. The function does not return a replacement value because actions do not consume callback return values.

Where to put the code

For a site-specific change, put the registration in a small custom plugin or in an appropriate theme extension point. A plugin keeps the behavior active when the site changes themes. Avoid placing customizations in WordPress core files. Keep the callback narrowly scoped and load it before the hook is fired; code added after an event has already run cannot respond to that occurrence.

Rank #2
Sale
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Action callbacks with arguments

Some actions provide one or more arguments. Your callback must declare only the values you intend to use, and the registration must state how many arguments WordPress should pass. Confirm the action reference before choosing that number rather than assuming every hook supplies the same data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Register your first filter

A filter callback receives the current value, changes it, and returns the result. Returning the value is not optional: if the callback returns nothing, the next code in the chain receives an unusable result.

Basic filter example

function wporg_add_suffix( $title ) {
    return $title . ' – My site';
}
add_filter( 'the_title', 'wporg_add_suffix' );

Whenever the_title is processed, the callback appends text and returns the new title. It does not echo markup or alter unrelated global state. Those side effects belong in an action or in a separately designed operation.

Filters with more than one argument

function wporg_adjust_title( $title, $post_id ) {
    return $title . ' #' . $post_id;
}
add_filter( 'the_title', 'wporg_adjust_title', 12, 2 );

The third argument, 12, is the priority. The fourth argument, 2, tells WordPress to pass two arguments to the callback. The first argument is normally the value being filtered; the other arguments are hook-specific context. The callback signature and the accepted-argument count must agree with the hook reference.

Priority controls execution order

When several callbacks use the same hook, WordPress orders them by priority. The default priority is 10. A callback at priority 9 runs before one at 10; a callback at 11 runs after it. If callbacks share a priority, they run in the order in which they were registered.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Registration Resulting order
add_filter( 'the_title', 'first', 9 ); Runs before callbacks at 10 or higher
add_filter( 'the_title', 'default_callback' ); Runs at the default priority of 10
add_filter( 'the_title', 'last', 11 ); Runs after callbacks at 10 or lower

Priority is useful when one callback must see another callback’s output or when your code must run before a later task. It is not a substitute for understanding the data contract. First confirm the hook and arguments, then choose the smallest priority adjustment that gives the required order.

Accepted arguments: match the hook’s contract

The fourth parameter of add_action() or add_filter() is the number of arguments WordPress should pass to your callback. A callback that declares two parameters should be registered to accept two arguments when the hook supplies them. Conversely, do not declare or request arguments that the hook does not provide.

Use the hook reference to verify:

  • Whether the hook is an action or a filter.
  • The order and meaning of every argument.
  • The maximum argument count available at that point.
  • When the hook fires in the request or rendering lifecycle.

This check prevents warnings, missing context, and accidental use of the wrong value. It also makes your code resilient when several callbacks are attached to the same hook.

How hooks run during a request

An action is fired with do_action(). WordPress reaches that statement and calls each registered callback in priority order. The callbacks may print, store, calculate, or trigger other work, but their return values do not replace anything in the action call.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A filter is applied with apply_filters(). WordPress starts with a value, sends it through each registered callback in order, and uses each returned value as the input for the next callback. The final value is then used by the code that called apply_filters().

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

This difference explains a practical rule: echoing inside a filter does not modify the value being filtered, while failing to return a value can break the filter chain. Keep output-oriented tasks on actions and transformation logic on filters.

Create custom hooks in a plugin

If you maintain a plugin, expose extension points so other developers can add behavior without editing your files. Use do_action() for an event and apply_filters() for a value that should be alterable.

do_action( 'wporg_before_settings' );
$value = apply_filters( 'wporg_settings_label', 'Settings' );

Other code can subscribe to the custom action or filter:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
function wporg_log_settings_start() {
    // Perform a task before the settings area is rendered.
}
add_action( 'wporg_before_settings', 'wporg_log_settings_start' );

function wporg_change_settings_label( $label ) {
    return $label . ' & options';
}
add_filter( 'wporg_settings_label', 'wporg_change_settings_label' );

Give custom hooks a distinctive prefix, document their argument order, and place them at a stable point in your plugin’s flow. For text or other data sent to the browser, a filter is generally the more flexible choice because another component can alter the value before output.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Remove an action or filter safely

Use remove_action() or remove_filter() when you need to detach a callback that was registered elsewhere. Removal works only when you identify the original hook and callable and use the same priority. The removal call must run after the original registration has occurred.

Best Value
Sale
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
function wporg_show_message() {
    echo '<p>Hello from an action.</p>';
}
add_action( 'wp_footer', 'wporg_show_message', 10 );

remove_action( 'wp_footer', 'wporg_show_message', 10 );

For methods, the callable identity must match the original method and object instance (or the same static method form). A different anonymous function, a different object, or a different priority is a different callback as far as removal is concerned. If the original code has not registered yet, your removal does nothing; place it at a later, reliable extension point.

A safe beginner workflow

  1. State the desired change. Decide whether you need to perform a task or transform a value.
  2. Find the exact hook. Confirm its name, type, timing, supplied arguments, and expected value.
  3. Create a unique callback. Prefix the function or method name for your project and keep its responsibility narrow.
  4. Register it explicitly. Use add_action() or add_filter(); specify priority and accepted arguments only when needed.
  5. Load it in the right place. Put the code in a plugin or suitable theme extension and ensure it loads before the hook fires.
  6. Test the contract. For an action, verify the task occurs. For a filter, verify the returned value reaches the caller and remains valid.
  7. Adjust order only when necessary. Change priority after confirming that another callback’s order is the actual cause.

Common failures and how to correct them

The callback never runs

Check that the plugin or theme code is active, the hook name is spelled exactly, and the registration executes before the hook fires. A correct callback attached too late cannot respond to an event that has already occurred.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The filter has no visible effect

Make sure the callback returns the changed value and that you used add_filter(), not add_action(). Also verify that the code path actually applies the filter you selected; not every title, setting, or output string passes through the same hook.

Arguments are missing or warnings appear

Compare the callback signature and the fourth registration argument with the hook reference. Request only the arguments supplied by that hook and put them in the documented order.

Another callback overwrites your result

Inspect priorities. A later filter can replace the value your callback returned, so move your callback earlier or later only after identifying the ordering requirement. For actions, a later callback may print additional output or perform a conflicting task.

Removing a callback changes nothing

Match the original hook name, callable, and priority, and run the removal after registration. With methods, use the same callable form and object identity. Anonymous callbacks that you cannot reference later are difficult or impossible to remove cleanly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A filter causes unexpected output or side effects

Keep filters focused on transforming their input and returning it. Move direct output, database writes, notifications, or unrelated global changes to an action or another dedicated operation.

Choosing the right hook at a glance

  • Need to print a footer message? Attach an action to the footer event.
  • Need to append text to a title? Attach a filter and return the revised title.
  • Need another plugin to react before your settings screen? Expose a custom action with do_action().
  • Need another plugin to rename a label? Expose a custom filter with apply_filters() and assign its returned value.
  • Need to disable an existing callback? Identify its exact callable and priority, then remove it after registration.

Hooks are small interfaces, but their contracts matter. Treat the hook type, argument list, priority, callback identity, and execution timing as part of the API. That discipline lets you extend WordPress cleanly while keeping custom behavior separate from core code.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.