How to hide certain meta key from admin-page/edit-post custom field in wordpress?

I’d like to hide my certain meta key from my edit-post custom field area.
Let’s say I have meta key with name “test1”.
I don’t want that to be appeared on my edit-post/page. However, I still want to show other custom fields,like let’s say “test2” “test3” “test4” etc.

I’ve read something about remove_meta_box(‘postcustom’,’post’,’normal’) but it hides all my custom fields.

Read More

I also have read about renaming your meta key with “_test1”. Yes, it’s hidden, but the problem occurs since there’s a plugin uses that meta key (“test1”) as well. So renaming the meta key starts with underscore is not a good idea.

Is there any code/function to hide certain custom fields? I don’t want users to edit that “test1” custom field but they still can edit other custom fields.

Thanks!

Related posts

Leave a Reply

1 comment

  1. You can hook into the is_protected_meta filter and return true for any custom field you want to hide.

    add_filter('is_protected_meta', 'my_is_protected_meta_filter', 10, 2);
    function my_is_protected_meta_filter($protected, $meta_key) {
        return $meta_key == 'test1' ? true : $protected;
    }