
Introduction:
One of the useful features of WordPress is the ability to create Custom Post Types, which allow developers to structure and organize content more effectively. Once you have created a Custom Post Type, you may want to add custom row actions to perform specific tasks. In this article, I will show you how to add custom links to the row actions of a Custom Post Type in WordPress.
Final result:


Adding the action function:
- The first step is to add an action function to modify the row actions of your Custom Post Type. This code will be added to your theme's functions.php file or your custom plugin:
add_filter( 'post_row_actions', 'wpdocs_custom_row_actions', 10, 2 );'<a href="/en/' . esc_url( 'http://tulink.com' ) . '/">' . __( 'Your Link Name', 'textdomain' ) . '</a>';
In this code, replace ‘your_custom_post_type_name’ with the name of your Custom Post Type. Change ‘http://tulink.com‘ to the URL you wish to link, and change ‘Your Link Name’ to the text you want to display for the link.
Adding dynamic parameters:
- If you want to make the link dynamic and dependent on specific post data, you can access the post information through the
$post. object. Here is an example of how to do this:
$actions['custom_link'] = '<a href="/en/' . esc_url( admin_url( 'admin.php/?page=your_custom_page&post=' . $post->ID ) ) . '">' . __( 'Your Link Label', 'textdomain' ) . '</a>';
This code will add the current post ID as a URL parameter.
Conclusion:
By adding custom links to the row actions of a Custom Post Type, you can improve the user experience and facilitate the management of your content in WordPress. Always remember to test changes in a development environment before applying them to your live site to ensure everything works correctly.
Do you need help with a web project?
Do you need help with a web project? Don't hesitate to contact me. I develop complete and customized solutions with WordPress and PHP, using modern tools and processes, HTML, CSS, SCSS, PHP, JavaScript, Bootstrap, and more. Ready? Send me a message and let's talk about your web project!
