2

I've been trying to find a way to hide/deactivate the Parent dropdown menu from the Posts -> Categories screen.
http://example.com/wp-admin/edit-tags.php?taxonomy=category

I was able to hide the "Slug" option through this function here:

// Admin - Global Terms Enabled
function disable_global_terms($enablefalse) {
   return 1;
}
add_filter( 'global_terms_enabled', 'disable_global_terms' );

Is there a way I can do the same for the Parent Drop Down menu without deleting that code from the main WP files so I would have to do this each time with each update?

2
  • What menu exactly are you talking about?
    – fuxia
    Jul 18, 2012 at 6:38
  • Hey Toscho, the Parent Drop Down menu that I'm talking about is located in a Post Type's submenu "Categories"... where you can view more categories of a Post Type, add a new category, give theme a description, etc.
    – Roc
    Jul 20, 2012 at 16:36

1 Answer 1

8

If you are deleting code from the main WordPress files, this means that you know your way around a whole bunch of PHP files, so it's time now to learn how to do things without touching core files.

Side note to the hook presented in the Question:
the filter global_terms_enabled only works for Multisite (/wp-includes/functions.php, line 3006).

In many cases, there are no hooks to modify the administrative interface, so the modification needs to be done with CSS or jQuery.
The solution bellow shows how to print scripts in a specific screen (edit-tags.php) of the admin_head-SCREEN-ID.php. There, many checks can be done, in this case URL params.

add_action( 'admin_head-edit-tags.php', 'wpse_58799_remove_parent_category' );

function wpse_58799_remove_parent_category()
{
    // don't run in the Tags screen
    if ( 'category' != $_GET['taxonomy'] )
        return;
    
    // Screenshot_1 = New Category
    // http://example.com/wp-admin/edit-tags.php?taxonomy=category
    $parent = 'parent()';
    
    // Screenshot_2 = Edit Category
    // http://example.com/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=17&post_type=post
    if ( isset( $_GET['action'] ) )
        $parent = 'parent().parent()';
        
    ?>
        <script type="text/javascript">
            jQuery(document).ready(function($)
            {     
                $('label[for=parent]').<?php echo $parent; ?>.remove();       
            });
        </script>
    <?php
}

Screenshot_1

Screenshot_1


Screenshot_2

enter image description here

1
  • It is not hiding on the edit screen. Any solution? Jul 22, 2019 at 7:16

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.