16

I have this in my functions.php

function remove_quick_edit( $actions ) {
    unset($actions['inline hide-if-no-js']);
    return $actions;
}
add_filter('post_row_actions','remove_quick_edit',10,1);

to remove the quick edit link in the backend when scrolling the list of published posts.

It works like a charm but it disable it even for the admin role. Is it possible to keep it showing only for the admin while still diabling for the rest? Thanks!

SOLVED thanks to jfacemyer! This is the full code to add in functions.php

function remove_quick_edit( $actions ) {
    unset($actions['inline hide-if-no-js']);
    return $actions;
}
if ( ! current_user_can('manage_options') ) {
    add_filter('post_row_actions','remove_quick_edit',10,1);
}
4
  • I believe the User Role Editor plugin will let you do this. Feel free to punch me in the head if I'm wrong. Mar 19, 2013 at 18:24
  • The user role plugin has made my site instable so I needed to disable it and I've added all the small pieces of code I needed in my functions.php making them available in case I want to replicate this project in the future. Unfortunately I'm missing the quick edit removal only for non admins...
    – user27309
    Mar 20, 2013 at 11:13
  • Please be careful: the solution you outlined doesn't remove "edit" from bulk actions select. In order to do it, you have to add this snippet of code add_filter( 'bulk_actions-edit-post', 'remove_from_bulk_actions' ); function remove_from_bulk_actions( $actions ){ unset( $actions[ 'edit' ] ); return $actions; } Jul 5, 2017 at 4:50
  • Could someone break this down for me. New to editing wordpress and I am a js person. For example what if you wanted to remove edit too? Like where did you get remove_quick_edit and add_filter from? Sep 13, 2022 at 18:25

4 Answers 4

13

Use current_user_can to wrap the add_filter call:

if ( current_user_can('manage_options') ) {
} else {
    add_filter('post_row_actions','remove_quick_edit',10,1);
}

manage_options is an Admin capability. If the current user can do it, he's an admin (on a vanilla WP installation).

See:

http://codex.wordpress.org/Roles_and_Capabilities

and

http://codex.wordpress.org/Function_Reference/current_user_can

1
12

Here is the code if you wish to remove the Quick Edit option from Pages as well:

function remove_quick_edit( $actions ) {
    unset($actions['inline hide-if-no-js']);
    return $actions;
}
if ( !current_user_can('manage_options') ) {
    add_filter('page_row_actions','remove_quick_edit',10,1);
    add_filter('post_row_actions','remove_quick_edit',10,1);
}
1

At least in WP 4.3.1 it is possible to use role name in current_user_can(). So the code may now look like this:

function remove_quick_edit( $actions ) {
  unset($actions['inline hide-if-no-js']);
  return $actions;
}
if ( !current_user_can('administrator') ) {
  add_filter('post_row_actions','remove_quick_edit',10,1);
}

Cleaner and more intuitive.

0

Include this in your function.php

add_action('admin_head', 'wc_my_custom_css');
function wc_my_custom_css() {
     echo '<style>
               .hide-if-no-js {
                  display:none !important;
               }
          </style>';
}
1
  • Disable and hide there is a difference. Please edit your answer.
    – Rakesh Roy
    Apr 12, 2021 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.