What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
WordPress hooks are predefined points where your code can run or alter data without editing WordPress core. Actions let a callback perform a task when an event occurs; filters let a callback receive a value, change it, and return the revised value. Once you understand that contract, add_action(), add_filter(), priorities, accepted arguments, custom hooks, and callback removal become predictable.
Antihost offers managed WordPress hosting with free migration, one-click staging and a 14-day free trial.
What a WordPress hook does
A hook is an extension point built into WordPress, a theme, or a plugin. At that point, the original code gives other code an opportunity to participate. Your code connects to the hook by registering a callback function or method. When WordPress reaches the hook during a request, it calls every registered callback according to its priority.
As an Amazon Associate I earn from qualifying purchases.
Free tools Windows power users keep installed
One-click scans. No signup required.
Hooks are the normal way to extend WordPress because they keep your changes outside core files. Core updates can replace edited files, while a callback registered by a plugin or an appropriate theme extension point remains separate from the code it extends. A useful beginner workflow is to identify the hook, confirm its type, check the arguments it supplies, then write the smallest callback that solves the problem.
Actions and filters: the difference that matters
Both hook types use callbacks, but they have different contracts. An action tells your code that a point in execution has been reached. A filter hands your code a value that must come back, possibly changed.
#1 Best Overall
- 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.
| Question | Action | Filter |
|---|---|---|
| Primary purpose | Perform work at a specific point. | Transform a value during execution. |
| Callback return value | Not used as a replacement value. | Required: return the original or modified value. |
| Typical work | Print markup, save data, send a notification, enqueue work, or trigger another task. | Change a title, text string, setting, query argument, or other value passed by WordPress. |
| Direct output | Appropriate when the action’s purpose is output, such as adding footer markup. | Normally inappropriate; return the changed value instead of echoing it. |
| Side effects | Expected when the task requires an operation. | Keep the callback focused on the supplied value and avoid unrelated global-state changes. |
| Registration function | add_action() |
add_filter() |
The names are separate for readability and intent, but WordPress dispatches both through its hook system. Choosing the correct type communicates what your callback is supposed to do and prevents subtle bugs, especially the common mistake of echoing from a filter without returning its input.
Registering an action callback
Define a callable function, then register it with the action name. This example prints a paragraph when WordPress reaches the wp_footer action:
function wporg_show_message() {
echo '<p>Hello from an action.</p>';
}
add_action( 'wp_footer', 'wporg_show_message' );
When the theme fires wp_footer, WordPress invokes wporg_show_message(). The callback performs output and does not return a replacement value to the action. In production code, use a distinctive prefix for your function names so they do not collide with functions from another plugin or theme.
Actions are also suitable for non-visual work. A callback can save information, send a notification, or trigger another operation when the relevant action fires. The hook reference determines which arguments, if any, are supplied, so do not assume every action passes the same data.
Rank #2
- 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.
Registering a filter callback
A filter callback receives a value, changes it if necessary, and returns the result. This example appends a suffix to a post title:
function wporg_add_suffix( $title ) {
return $title . ' – My site';
}
add_filter( 'the_title', 'wporg_add_suffix' );
If the callback decides no change is needed, it should still return the value it received. Do not print the result from a filter; returning it allows the rest of WordPress and other callbacks to continue processing the value. Keep filter callbacks narrowly scoped and avoid unrelated side effects such as changing global state.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsFilters are especially useful for text or data that will eventually be rendered in a browser. Another component can attach to the same filter and make a later transformation, provided each callback honors the return-value contract.
Priority and accepted arguments
The full registration form is:
add_filter( 'hook_name', 'callback_name', 10, 1 );
add_action( 'hook_name', 'callback_name', 10, 1 );
The third parameter is the priority. The default is 10. A callback at priority 9 runs before one at 10; a callback at 11 runs afterward. When callbacks share the same priority, they run in the order in which they were registered.
Rank #3
- 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.
The fourth parameter is the number of arguments your callback accepts. It must not exceed the number documented for that particular hook. A callback can accept fewer arguments than a hook supplies, but declaring an argument that the hook never passes will cause an error. Check the specific hook reference before choosing this number.
function wporg_adjust_title( $title, $post_id ) {
return $title . ' #' . $post_id;
}
add_filter( 'the_title', 'wporg_adjust_title', 12, 2 );
Here the callback runs after callbacks at the default priority of 10, and WordPress passes two values: the title and the post ID. Priority is an ordering tool, not a guarantee that your code will run before every other plugin; another callback can choose an earlier or later number.
How to find the right hook
- Describe the change in one sentence. For example: “Add markup in the footer” is an action-shaped requirement, while “change the displayed title” is a filter-shaped requirement.
- Locate the hook reference. Confirm the exact hook name, whether it is an action or filter, when it fires, and the arguments it supplies.
- Check the lifecycle context. A hook may fire during an administrative request, a front-end page render, a save operation, or another stage. Registering code at the wrong stage can make it run too early, too late, or in a context you did not intend.
- Write a narrowly scoped callback. Give it a unique prefix, validate the values it receives, and return the required value for filters.
- Register from a plugin or suitable theme extension point. Do not modify WordPress core files to make the change.
For a game site, the same process applies whether you are adding a small notice to a template, changing a review title, or adjusting metadata generated by a plugin. The subject matter does not change the hook contract; the hook’s documentation does.
Creating custom hooks in a plugin
If you maintain a plugin, you can provide extension points for other developers instead of requiring them to edit your files. Use do_action() when you want to announce that an event has occurred, and apply_filters() when you want to let another component alter a value.
Rank #4
- 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
do_action( 'wporg_before_settings' );
$value = apply_filters( 'wporg_settings_label', 'Settings' );
Other code can subscribe to these extension points in the same way it subscribes to core hooks:
add_action( 'wporg_before_settings', 'wporg_before_settings_callback' );
add_filter( 'wporg_settings_label', 'wporg_settings_label_callback' );
The custom action does not return a value. The custom filter does: whatever callbacks change must be assigned back to a variable or passed onward. Use distinctive, documented names for custom hooks so consumers can understand when they fire and what arguments they receive. For text sent to the browser, a filter is generally the more flexible interface because another component can alter the final output.
Removing an action or filter
Use remove_action() or remove_filter() when you need to detach a callback registered elsewhere. Removal only works when the identifying details match the original registration:
- The exact hook name.
- The same callback, including the object or class context when the callback is a method.
- The same priority used during registration.
- Execution after the original callback has been added.
For example, if a callback was registered at priority 12, removing it at the default priority of 10 will not match it. Likewise, naming a method without the same callable structure used at registration leaves the original callback attached. Put the removal code on an action that runs after the code you are overriding has registered its callback; otherwise there is nothing for WordPress to remove yet.
Best Value
- 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.
Common beginner mistakes and fixes
Echoing from a filter
Symptom: duplicated or misplaced text, followed by the original value appearing as well. Fix: stop printing inside the filter and return the modified value.
Forgetting the filter return
Symptom: a title, label, or setting becomes empty or behaves inconsistently. Fix: return the input when unchanged and the revised value when changed.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Using the wrong argument count
Symptom: a PHP warning or an argument-related error. Fix: check the hook reference and make the fourth registration parameter match the number of arguments your callback actually accepts.
Assuming priority changes data automatically
Symptom: a callback runs, but another callback later replaces its result. Fix: choose a priority deliberately and inspect the other registrations when ordering matters. A later filter can legitimately transform the value again.
Trying to remove a callback too early
Symptom: remove_action() or remove_filter() appears to do nothing. Fix: use the original callback and priority, and execute the removal after registration.
Editing core files
Symptom: the change disappears after an update. Fix: move the logic into a plugin or an appropriate theme extension point and connect it with a hook.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteA safe workflow for shipping hook code
- Confirm the contract. Write down whether the hook is an action or filter and list every argument documented for it.
- Choose a unique callback name. Prefix functions and custom hook names to reduce collisions.
- Keep one responsibility per callback. An action should perform its task; a filter should transform its supplied value.
- Select priority only when needed. Start with the default of 10, then adjust when ordering with another known callback requires it.
- Register in the correct context. Ensure the code loads before the hook fires and does not run in an unintended request type.
- Test both changed and unchanged paths. A filter must preserve valid input when its condition is false, and an action should not emit output where the surrounding context cannot accept it.
- Document custom interfaces. State when your custom hook fires, which arguments it supplies, and whether a filter’s value must be returned.
Thinking in contracts makes hooks easier to debug: actions answer “what task should happen here?”, while filters answer “what value should continue through the pipeline?”
Quick Recap
Key takeaways
- Use
add_action()for work performed at an event andadd_filter()for values that must be returned, possibly changed. - Priority 10 is the default; lower numbers run earlier, higher numbers later, and equal priorities follow registration order.
- The accepted-argument count must match the documented hook signature.
- Create extension points with
do_action()andapply_filters()rather than asking users to edit plugin files. - Removal requires the original callback details and must happen after registration.
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.




