php - admin panel - How to remove "delete" button from category editing page

admin2025-01-08  3

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

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>';
}

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

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>';
}
Share Improve this question asked Dec 28, 2020 at 17:17 Antanas IgnasAntanas Ignas 11 bronze badge 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
Add a comment  | 

3 Answers 3

Reset to default 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/

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>';
}

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>';
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736270774a1454.html

最新回复(0)