Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use media_row_actions filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
August 4, 2022
5 minutes read

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.

Access Premium WordPress Plugins

Contact Us

If you’re having any trouble using this hook or need customizations, please contact our team. We’re here to help!

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

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.