Instead of making the custom field read-only, you can hide a custom field by prefixing the name of the custom field with an underscore.
e.g _custom_field_name
You can hide the field by disabling the input boxes using replacing CUSTOM_FIELD_NAME
with the name of your custom field.
jQuery(document).ready(function () {
metaName = jQuery("#postcustom input[value="CUSTOM_FIELD_NAME"]").attr("id");
metaValue = metaName.replace("key", "value");
metaName.prop('disabled', true);
metaValue.prop('disabled', true);
})
You would need to put the jQuery code in a js file in your Parent or Child theme and enqueue it on the post.php
page using:
function add_admin_scripts( $hook ) {
if ( $hook == 'post-new.php' || $hook == 'post.php' ) {
wp_enqueue_script( 'myscript', get_stylesheet_directory_uri().'/js/myscript.js' );
}
}
add_action( 'admin_enqueue_scripts', 'add_admin_scripts', 10, 1 );