0

i want to disable, hide or remove delete buttons from category page

enter image description here

I tried editing functions.php with no luck:

add_action('admin_head', 'hide_category_buttons');

function hide_category_buttons() {
  echo '<style>
    .taxonomy-category tr:hover .row-actions {
        visibility: hidden;
    }
  </style>';
}
2
  • 1
    You might do better removing the delete_terms capability from the users you want to hide the button from.
    – Rup
    Commented Dec 29, 2020 at 11:41
  • Right, Hiding admin UI options with CSS is a hacky solution, and while it's not such an easy method, using WP Roles and Caps is the technically right way to go - wordpress.org/support/article/roles-and-capabilities
    – Q Studio
    Commented Dec 29, 2020 at 17:09

3 Answers 3

1

Wordpress has a filter for action links.

apply_filters( "{$taxonomy}_row_actions", $actions, $tag );

For product_cat taxonomy:

add_filter('product_cat_row_actions', function($actions, $term) {
    unset($actions['delete']);
    return $actions;
});

https://developer.wordpress.org/reference/hooks/taxonomy_row_actions/

0

There is some modification in your code, insted of this class .taxonomy-category tr:hover .row-actions apply css on this class .taxonomy-category .row-actions span.delete, it willl work.

Here is whole code.

add_action('admin_head', 'hide_category_buttons');

function hide_category_buttons() {
   echo '<style>
     .taxonomy-category .row-actions span.delete {
        visibility: hidden;
     }
   </style>';
}
6
  • It's not working, but is it the right place to put this code in functions.php of my theme if im modifying admin panel, should this code go some where else? Commented Dec 28, 2020 at 17:57
  • Have you try with my code ? It's working correctly. function.php file is right place to put this code.
    – Veerji
    Commented Dec 28, 2020 at 17:59
  • For some reason it's not working even with your code :( Commented Dec 28, 2020 at 18:10
  • Yes, I see that. For twentyseventeen theme it's working and for other themes it's not working.
    – Veerji
    Commented Dec 28, 2020 at 18:15
  • I'm using oceanwp, do you have any ideas? Commented Dec 28, 2020 at 18:17
0

Probably your CSS selector is wrong. You can filter the admin pages where your function runs and you can use an universal selector.

global $pagenow;   
 
if (( $pagenow == 'edit-tags.php' ) && ($_GET['taxonomy'] == 'product_cat') && 
($_GET['post_type'] == 'product') ) {
    add_action('admin_head', 'hide_category_buttons'); 
}

function hide_category_buttons() {
  echo '<style> .row-actions > .delete { display: none; }  </style>';
}
4
  • How does that target the 'delete' button specifically?
    – Rup
    Commented Dec 29, 2020 at 11:59
  • Oh, thought we need to remove all of the buttons. Use this to target the delete button: <style> .row-actions > .delete { display: none; } </style> Commented Dec 29, 2020 at 15:12
  • That works, thanks!! Commented Dec 29, 2020 at 20:14
  • Can you accept my answer, please? Commented Dec 29, 2020 at 21:31

Your Answer

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

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