This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Using WordPress hooks can be a game-changer for your development process. Let’s dive into the media_row_actions filter which allows you to modify the action links for each attachment in the Media list table. This hook is quite handy when you need to customize media actions without altering core files.
To get started with the media_row_actions filter, you first need to register it using add_filter
. You can do this in your theme’s functions.php
file or in a custom WordPress plugin. At WePlugins, we always recommend creating a custom plugin for hooks to avoid issues when updating your theme.
Below are three live examples demonstrating how to use the media_row_actions filter.
Example 1: Basic Usage
This example shows how to modify the media row actions by adding a new action link.
function weplugins_modify_media_row_actions($actions, $post, $detached) { // Add a custom action link $actions['custom_action'] = 'Custom Action'; return $actions; } add_filter('media_row_actions', 'weplugins_modify_media_row_actions', 10, 3);
Example 2: Conditional Action Links
In this example, we’ll add a conditional action link that only appears for image attachments.
function weplugins_modify_media_row_actions_conditional($actions, $post, $detached) { if ($post->post_mime_type == 'image/jpeg') { $actions['custom_image_action'] = 'Custom Image Action'; } return $actions; } add_filter('media_row_actions', 'weplugins_modify_media_row_actions_conditional', 10, 3);
Example 3: Removing a Custom Action
Sometimes you might need to remove a previously added action. This example shows how to do that.
function weplugins_modify_media_row_actions_remove($actions, $post, $detached) { // Remove a custom action link unset($actions['custom_action']); return $actions; } add_filter('media_row_actions', 'weplugins_modify_media_row_actions_remove', 10, 3);
If you need to remove a registered hook, use the remove_filter
function as shown below:
remove_filter('media_row_actions', 'weplugins_modify_media_row_actions', 10, 3);
Be sure to provide the same callback function name, priority, and number of arguments when removing the hook callback.
Contact Us
If you’re having any trouble using this hook or need customizations, please contact our team. We’re here to help!
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.