2

I need to hide, and not to remove the attributes meta box in the backend.

The following code is removing the metabox:

function hide_meta_box_attributes() {
remove_meta_box('pageparentdiv', 'post', 'normal'); } 
add_filter('add_meta_boxes', 'hide_meta_boxes_attributes');

The problem is, that I am running hierarchical posts, which means I need to have the possibility to have posts and subposts which is enabled by this metabox. When I am removing the metabox, the functionality is not working anymore. But for my authors, I need to hide these attributes metabox.

Anybody has a clue how to get a solution on this?

1 Answer 1

4

The get_hidden_meta_boxes function (source link) provides two filters that you can use to hide the meta box. (Pick just one of them.)

The first is default_hidden_meta_boxes (source), adding the metabox to the $hidden array will hide the metabox by default, but the user can select the screen options tab and choose to enable it.

The second filter is called hidden_meta_boxes (source), adding the metabox to the $hidden array here should just hide that metabox, period.

Example using hidden_meta_boxes filter:

function hide_meta_box_attributes( $hidden, $screen) {

    $hidden[] = 'pageparentdiv';
    return $hidden;

} 
add_filter('hidden_meta_boxes', 'hide_meta_box_attributes', 10, 2);
3
  • Hey TomHarrigan many thanks for this solution. It is working exactly how I need it!
    – Traveler
    Commented May 27, 2014 at 10:17
  • 1
    @Traveler you should accept this answer as it solved your problem. If you don't know how, just check next to the answer that Tom gave, there are an up/down arrow. Just below is a checkmark, you should click on that. By doing this, you will not only reward the person reputation that gave you the solution, but you also gain reputation for yourself. The higher reputation you have, the more willing others will be to help you. And most of all, this answer will help others that visit the site as well. So you are helping to keep your question and Tom's answer constructive Commented Jun 6, 2014 at 6:51
  • Be advised that this only works on NEW users OR users who haven't already made any customisations to their screen options; perhaps another way to handle it if you run into this issue?
    – Brett
    Commented Jun 1, 2020 at 18:33

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.