• Hi All,

    Re: I’m trying to remove some meta boxes from post editor and I’m using Neve theme

    I have tried the following code many times, however it has not changed a bit the outlook of post editor

    function remove_meta_boxes() {
      # Removes meta from Posts #
      remove_meta_box('postexcerpt','post','normal' ); 
      remove_meta_box('postcustom','post','normal');
      remove_meta_box('trackbacksdiv','post','normal');
      remove_meta_box('commentstatusdiv','post','normal');
      remove_meta_box('commentsdiv','post','normal');
      remove_meta_box('tagsdiv-table_tags','post','normal');
      remove_meta_box('tagsdiv-post_tag','post','normal');
      remove_meta_box('comment-hacks-reroute','post','normal');
    
    }
    add_action('admin_init','remove_meta_boxes');

    I want to leave the Category, featured image, status & visibility and permalink in sidebar of post editor and remove every other metabox such as Author, Excerpt, Tags, Yoast Comment Hacks, Discussion, Post Attributes, Post Settings,

    • This topic was modified 2 years, 9 months ago by Yui.
    • This topic was modified 2 years, 9 months ago by Jan Dembowski. Reason: ;wpev
Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi, flyers123, are you using the Gutenberg or the Classic Editor?

    If you’re using Gutenberg, you want to take a look into the remove_post_type_support function: https://developer.wordpress.org/reference/functions/remove_post_type_support/

    In Gutenberg, meta boxes are instead referred to as panels.

    That function may not remove all the support you wish. This answer on the WordPress StackExchange provides more information about this and the JavaScript approaches: https://wordpress.stackexchange.com/a/339437/190079

    It looks like you are hooking to the wrong hook. If you look at https://developer.wordpress.org/reference/functions/register_and_do_post_meta_boxes/
    you’ll see that the core meta boxes are added first, and then the hook 'add_meta_boxes' is called. So there is nothing to remove at 'admin_init' time.
    Change your hook to 'add_meta_boxes' and use a large number for priority.

    Thread Starter flyers123

    (@flyers123)

    Hi Joy, i’m not good with technical stuff. I just happened to find that cose and I tried it. I’m using block editor instead of classic editor.

    Can you please advise what do you mean by large number of priority?

    Do you mean if I change the following to this it should work

    add_action(‘add_meta_boxes’,’remove_meta_boxes’)

    Thank you in advance

    Thread Starter flyers123

    (@flyers123)

    Hi Ian,

    Thank you for your response.

    My knowledge in coding is next to nothing.

    I’m using block editor.

    I would appreciate if you can please help me with full code. I want to remove those metaboxes

    ‘Author’
    ‘excerpt’
    ‘trackbacks’
    ‘custom-fields’
    ‘comments’ (also will see comment count balloon on edit screen)
    ‘revisions’ (will store revisions)
    ‘page-attributes’ (template and menu order) (hierarchical must be true)
    ‘post-formats’ removes post formats, see Post Formats
    ‘Post settings’
    ‘Yoast comments hack’ – a comments plugin
    metabox

    Thank you in advance

    Are you trying to change it just for yourself or for every user you might have on your site?
    The editor (both block and Classic) is configurable. For Classic, it’s like other admin screens, where you can click on Screen Options at the top to choose what is shown. For the block editor, there is a three dot menu at the top, and if you choose Preferences, you can find the Panel choices.

    Thread Starter flyers123

    (@flyers123)

    Hi Joy,

    I’m trying to change the option for other users except administrators

    I’m aware of the configurable options as shown in the screenshot but they only work for admins

    You can read about the priority parameter here: https://developer.wordpress.org/reference/functions/add_action/

    Thread Starter flyers123

    (@flyers123)

    Thanks Joy for the reference link

    However, my understanding in coding is next to nothing, hence why I have asked for help in here.

    Are you able to put together the code?

    Thank you in advance

    The core code is using the default priority of 10.
    So add_action(‘add_meta_boxes’,’remove_meta_boxes’, 99); might work.
    Your code for each individual box might need different third parameters. You can check in the first link I gave so you can match the “add” to the “remove” or it won’t find it to remove.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Hide WordPress Meta Boxes in the Post Editor’ is closed to new replies.