WordPress: How to Hide Custom Field Meta Key from Custom Fields panel

WordPress - the logo
I learned this trick when someone asked about How to Hide Custom Fields Meta Key from Custom Fields panel. This trick useful when you want to hide certain Custom Fields Meta Key and Value from client or authors
Custom Fields
Add following code to functions.php

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

This code to hide a Custom Field Meta Key, just change mymetakey_no1 to meta key name that you wanted to hide. What if you want to hide two Meta Key?, add following to functions.php underneath above code
[/php]
add_filter(‘is_protected_meta’, ‘my_is_protected_meta_filter2’, 10, 2);
function my_is_protected_meta_filter2($protected, $meta_key) {
return $meta_key == ‘mymetakey_no2’ ? true : $protected;
}
[/php]


Comments

One response to “WordPress: How to Hide Custom Field Meta Key from Custom Fields panel”

  1. Eder Ribeiro Avatar
    Eder Ribeiro

    Hello, great trick! thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: