Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Make a custom field in admin post.php read only

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 );

Related Posts:

  1. Get attachment meta (I need attachment ID, unsure how to find it)
  2. Related Post Category Filter
  3. How to add a checkbox element to attachments editor with example
  4. How to remove the Theme Customization Button from the dashboard and themes options page?
  5. What filters are applied to the_content function?
  6. Change admin bar to default:off
  7. How to modify an image block in Gutenberg WordPress 5?
  8. Edit srcset and sizes attributes in Gutenberg image, cover and gallery – blocks
  9. wp_get_attachment_image_attributes not working for me
  10. How to sanitize select box values in post meta?
  11. Strategy to get post meta for use outside the loop
  12. Display a different theme for not logged-in users
  13. Run shortcode before filters
  14. Add class to before_widget for all widgets with a dropdown and a counter
  15. How to Auto Approve Comments on a Specific Page?
  16. Get password when user registers and save it sha1 into database
  17. Set Expiration Date of a Post from the Frontend with wp_insert_post
  18. Passing variable in hooks and filter
  19. Change loop order via form or link (jquery, not URL)
  20. Why is unfiltered html allowed in custom fields for author / contributor roles?
  21. WordPress nav_menu_css_class theme filter is not being called
  22. customizing the_password_form filter
  23. Using the theme options to change background
  24. WordPress Genesis Child Theme Filter divs
  25. Change file name from wp_generate_attachment_metadata
  26. wp_editor() usage in custom meta box
  27. Is there a need for nonce with Post Metabox?
  28. Simple way to get two language WP site
  29. Custom Field returning Numerical Value for Image rather than URL
  30. Metadata Query when storing data as array possible?
  31. Highlight “Show all” item in wp_list_categories
  32. When trying to override plugin’s function by theme, my filter executes two times, I want it to run only a single time
  33. Custom post fields
  34. How can I create a list of page titles from custom meta values?
  35. Menu item added in wp_nav_menu_items filter is never highlighted
  36. filtering custom post types via meta data drop down
  37. Should I use add_filter for functions in function.php of the theme?
  38. How do I Add images uploaded in the post to a default custom field
  39. Pass variable to hook. Its possible?
  40. Custom Field created in add_meta_boxes reappearing itself again in the default Custom Metabox
  41. How do you replace content generated by custom fields with custom blocks in Block Editor?
  42. Sort wp_query by sum of two meta fields
  43. What’s the best practice way of handling custom fields in different post formats?
  44. WordPress taxonomy and archive custom class
  45. Custom page template with custom fields
  46. Filter categories used with Custom Structure Permalink
  47. Redirect to another page using contact form 7? [closed]
  48. Wp Super Cache stops the update of a Post Meta
  49. How to wrap all titles generated by Gutenberg “Heading” block with tag
  50. Where WordPress Stores The Custom Fields Values
  51. Replace single_template filter with what for default posts?
  52. Unique design inside a specific category’s url
  53. How to rotate every letter in a title
  54. How to show specific post meta?
  55. How to disable thumbnail filter for a specific template part or image size?
  56. How to display childrens custom fields?
  57. CSS class on last post in loop ( custom query )
  58. How to change footer credit text in Twenty Twenty One theme with a hook?
  59. Running a function on post update with new post meta
  60. Use a filter on menu items that have children
  61. Modify available templates (in dropdown)
  62. What is the best way to build home pages with a lot of sections for distributable themes [closed]
  63. How to add post meta fields to an article’s as meta elements
  64. tiny_mce_before_init: ‘exact’ => true has no effect
  65. Is it possible to set a variable for get_post_meta?
  66. Injecting pre-defined text from custom page template to editor
  67. Let user to add input fields on theme option page
  68. How to conditionally add a wp_filter
  69. Filter didn’t work on content class (hybrid_post_attributes)
  70. How to set default values for edit_post_link() in my theme?
  71. How to use shortcode inside of shortcode in theme
  72. Footnotes in custom fields
  73. Tiny MCE custom styles, and preview in the backend
  74. Add image URL automatically to custom field?
  75. content filter (add_filter) for category description?
  76. Filter search posts by post meta?
  77. How can I sort my loop based on meta data, using a form?
  78. Pagination don’t work with active filters
  79. How can I add a field for featured image on backend of a custom Taxonomy?
  80. How to register dynamic settings in WordPress Customizer?
  81. restrain filter on get_the_excerpt to queried item in stead of current post
  82. WordPress wp_get_current_user returning blank values until refresh
  83. Alternative solution for script_loader_tag?
  84. Alt header logo and link for specific pages
  85. How to fix a conflict cause by my theme with Woocommerce and/or Gravity Forms?
  86. WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
  87. I want to change the author name
  88. Hook in parent theme Menu function
  89. How do I remove p tag *insertions*? Disabling `wpautop` removes manual tags
  90. How to add custom nav_menu_css_class to certain menu only?
  91. How to manipulate wordpress template tags’ output
  92. what is do_action(); in wordpress? [duplicate]
  93. change attachment custom field onChange event
  94. How to add custom field option with menu?
  95. Change default options on attachment page
  96. Suppress the_content filter in a nested loop
  97. Add custom field to existing meta box?
  98. apply_filters to featured image
  99. Add rel to all images in a post
  100. Add Field To All Pages
Categories theme-development Tags custom-field, filters, post-meta, theme-development
Showing All Media from All Multisites
Outputting custom field on home.php not outside of blog list

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress