Hi it’s been a while now since my last posts so I’m thinking to add new interesting tips and snippet, sounds great right? of course, this simple snippet remove or unset row-actions in your WordPress dashboard that says “dit”, “Quick Edit”, “view” and etc., this snippet is useful if you don’t want that functionality display in dashboard tables like in your custom post type, e.g. slider.

Solution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// filter row-actions
add_filter( ‘post_row_actions’, ‘rys_remove_row_actions’, 10, 1 );
/**
* @desc    Update row actions
*/
function rys_remove_row_actions ( $actions )
{
    if( get_post_type() === ‘slider’ ) { //remove “slider” post_type to whatever post_type you want the row-actions to hide
        unset( $actions['view'] );    // view
        unset( $actions['inline hide-if-no-js'] );  // quick edit
        unset( $actions['edit'] );    // edit
        unset( $actions['trash'] );    // trash
    }
    //return $actions array
    return $actions;
}

Additional Tip:

For hierarchical post types simply update the filter above to this.
1
add_filter( ‘page_row_actions’, ‘rys_remove_row_actions’, 10, 2 );
If you want to remove all row-actions simply return an empty array like this
 PHP
1
2
3
4
5
6
7
function rys_remove_row_actions ( $actions, $post )
{
    if ( get_post_type() === ‘page’ ) {
        return array();
    }
    return $actions;
}
That’s it, pretty easy, enjoy blogging share your thoughts below on the comment.

0 comments:

Post a Comment

 
Top