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]

WordPress: Shortcode in Custom Field


Normally wordpress does not run shortcode that you put into a custom field. By default, Custom Fields display whatever value you enter, as plain-text, so if you try entering a shortcode, (in the format [shortcode] VALUE [/shortcode]) you’ll end up displaying the entire text, including the tags.

Add the following in your template file, it can be single.php or page.php or else

echo apply_filters('the_content', get_post_meta($post->ID,'your_custom_field',true)); 

or

$shortcode=get_post_meta($post->ID,'your_custom_field',true);
echo do_shortcode($shortcode);