Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11A custom meta box is a panel added to a WordPress edit screen for data that does not belong in the title or content editor. You create it by registering add_meta_box() on an add_meta_boxes hook, rendering the controls in a callback, and saving the submitted value with a guarded save_post handler. The complete pattern below works for regular posts and can be adapted to a custom post type, including sites using the Block Editor.
Antihost offers managed WordPress hosting with free migration, one-click staging and a 14-day free trial.
What a custom meta box does
WordPress stores information about a post in more places than the main editor. A meta box gives editors a labeled panel for one related value or a small group of values, such as an internal note, an author bio field, a source URL, or a product reference number. The panel belongs to the post being edited; it is not a separate content type.
As an Amazon Associate I earn from qualifying purchases.
A plugin is the safest home for this functionality because the field remains available if the site changes themes. A theme can contain the same code when the field is inseparable from that theme, but moving to another theme would then remove the editing interface even though the metadata remains in the database.
The interface and storage are separate concerns:
- Interface:
add_meta_box()creates the panel and a render callback outputs its fields. - Storage: post metadata is normally written with
update_post_meta()and read withget_post_meta(). - Protection: a nonce, capability check, autosave/revision guard, and field-specific sanitization protect the save operation.
Plan the field before writing PHP
Choose the edit screen
The fourth argument to add_meta_box() identifies the screen. Use post for standard blog posts, page for pages, or the slug of a custom post type. A box registered for one screen will not automatically appear on another.
#1 Best Overall
- [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
- [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
- [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
- [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
- [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
Choose context and priority
The context controls placement: normal places the box in the main editing area, side places it in the sidebar, and advanced places it in the additional metabox area. The priority (high, default, low, or core) influences its order relative to other boxes. Placement is an editorial decision: a long text field usually needs normal, while a short flag or identifier can fit in side.
Define a stable meta key
Pick a key that is unique to your project, such as _acme_details. Prefix function names, nonce names, and keys with a project or vendor prefix. This prevents accidental collisions with another plugin and makes the database schema understandable later.
Recommended Free Tools
Decide what an empty value means
An empty submission can either remain as an empty meta value or remove the key entirely. Make that behavior explicit in the save callback. Readers of the data should not have to guess whether a missing key and an empty string mean different things.
Complete minimal implementation
Put the following in a plugin file or in the code location your project uses for plugin functionality. It registers a details box for posts, displays the existing value, and saves a plain-text textarea securely.
<?php
// Register the box for posts.
add_action( 'add_meta_boxes', 'acme_register_meta_box' );
function acme_register_meta_box() {
add_meta_box(
'acme_details',
__( 'Extra details', 'acme' ),
'acme_render_meta_box',
'post',
'normal',
'default'
);
}
// Render the field and a nonce.
function acme_render_meta_box( WP_Post $post ) {
$value = get_post_meta( $post->ID, '_acme_details', true );
wp_nonce_field( 'acme_save_details', 'acme_details_nonce' );
?>
<p>
<label for="acme_details_field"><?php esc_html_e( 'Details', 'acme' ); ?></label>
<textarea id="acme_details_field" name="acme_details_field" rows="4" class="widefat"><?php echo esc_textarea( $value ); ?></textarea>
</p>
<?php
}
// Validate and save.
add_action( 'save_post', 'acme_save_meta_box' );
function acme_save_meta_box( $post_id ) {
if ( ! isset( $_POST['acme_details_nonce'] )
|| ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['acme_details_nonce'] ) ), 'acme_save_details' ) ) {
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( wp_is_post_revision( $post_id ) ) {
return;
}
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
if ( ! isset( $_POST['acme_details_field'] ) ) {
return;
}
$value = sanitize_textarea_field( wp_unslash( $_POST['acme_details_field'] ) );
update_post_meta( $post_id, '_acme_details', $value );
}
This is a pattern rather than a universal drop-in. Change the post type, labels, key names, capability, sanitizer, and empty-value behavior to match the field and the workflow.
How the registration and render callbacks work
Register on the correct hook
add_action( 'add_meta_boxes', ... ) runs the registration function at the point WordPress is preparing edit-screen boxes. Inside it, add_meta_box() receives six important values:
Rank #2
- 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
- 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
- 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
- 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
- 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
- A unique box ID (
acme_details). - The visible title (
Extra details). - The callback that prints the controls.
- The screen (
post). - The context (
normal). - The priority (
default).
If the box belongs to only one post type, the more specific add_meta_boxes_{post_type} action keeps the registration scoped to that screen. The general action is useful when one function intentionally registers boxes for several screens.
Load and escape existing data
The render callback receives the current WP_Post object. get_post_meta( $post->ID, '_acme_details', true ) retrieves the single value so an editor sees previously saved text. Escape at output time for the HTML context: use esc_textarea() inside a textarea, esc_attr() for an attribute, and esc_html() for ordinary text. Do not print a stored value directly into markup.
Add a nonce to the box form
wp_nonce_field() emits a hidden token tied to the save action. The field name and action string must match the values checked by the save handler. A nonce helps establish that the request came from the expected editing form; it is one part of the security sequence, not a replacement for authorization.
Write a defensive save handler
Verify the expected request
Check that the nonce field exists before reading it. Remove WordPress’s request slashes with wp_unslash(), sanitize the nonce string, and pass it to wp_verify_nonce(). If the token is absent or invalid, return without writing.
Ignore autosaves and revisions when appropriate
The save_post action can run for more than one kind of update and can fire more than once during a single update event. Skip autosaves when the field should change only from an intentional edit, and skip revisions so a revision operation does not overwrite the current value. The sample uses DOING_AUTOSAVE and wp_is_post_revision() for those guards.
Check authorization
Use current_user_can( 'edit_post', $post_id ) or the capability appropriate to your post type before accepting input. A nonce does not prove that a user is allowed to edit the post.
Rank #3
- [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
- [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
- [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
- [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
- [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
Require the field before reading it
When a field is not present in $_POST, return rather than treating the missing value as an instruction to erase data. This also prevents unrelated saves from changing the metadata.
Sanitize for the field type
The example uses sanitize_textarea_field() because the value is plain text from a textarea. Use a URL sanitizer for a URL, a suitable scalar sanitizer for a short identifier, and strict allow-list handling for structured values. Always unslash submitted values before sanitizing. Sanitization is not the same as output escaping; escape again when rendering in HTML.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Persist deliberately
update_post_meta() updates an existing key or creates it when necessary. For a design that treats an empty submission as deletion, call delete_post_meta() when the sanitized value is empty; otherwise update the key. If multiple values are intentional, define whether the key stores one scalar or a collection and keep that schema stable.
Add the box to a custom post type
Replace 'post' in the registration call with the custom post type’s slug. For a box used only by that type, register it on the post-type-specific action:
add_action( 'add_meta_boxes_book', 'acme_register_book_meta_box' );
function acme_register_book_meta_box() {
add_meta_box(
'acme_book_details',
__( 'Book details', 'acme' ),
'acme_render_book_meta_box',
'book',
'normal',
'default'
);
}
A custom post type can also declare a register_meta_box_cb option when it is registered. That callback is another place to attach the box registration. Keep both the display and save logic restricted to the intended post type so a field from one content model cannot be written onto another.
Confirm that the post type supports the editor features your workflow needs. A box can be registered successfully while the surrounding edit screen lacks the capabilities or supports expected by your authors.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #4
- Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
- Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
- All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
- Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
- Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
Using a meta box with the Block Editor
The Block Editor continues to support most existing legacy meta boxes, so the server-rendered pattern above remains useful for a small field and for maintaining an established plugin. The box appears alongside the block-based editor rather than becoming a block itself.
Choose a newer block-based or sidebar approach when the field needs live previews, richer editor controls, reusable components, or a JavaScript-driven experience. That approach generally requires more editor integration work, but it can make the field feel like part of the block workflow instead of a legacy panel.
If a block, an external client, or another REST consumer must read or edit the value, register the metadata explicitly:
register_post_meta(
'book',
'_acme_details',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
)
);
The post type also needs custom-fields support for registered metadata to be available through the REST API. A classic box can still be the authoring UI while registered metadata supplies the integration point for blocks or other clients.
Choose the right editing approach
| Approach | Editor integration | Implementation profile | Best fit |
|---|---|---|---|
| Classic meta box | Supported in the Block Editor for most existing boxes | Server-rendered PHP form with a save handler | Small fields, straightforward forms, and existing plugins |
| Block or editor sidebar | Native block-based controls and live editor interaction | More JavaScript and build complexity | Live previews, richer controls, and reusable editor components |
| REST-enabled registered meta | Usable by blocks and REST clients when conditions are met | Requires register_post_meta(), show_in_rest, and post-type custom-fields support |
Data that must be consumed or edited outside the PHP form |
Base the decision on author experience, backward compatibility, REST exposure, and the amount of JavaScript your project can maintain. REST registration does not by itself create a visible editing panel; it exposes a deliberately defined data interface.
Understand where the value is stored
Post metadata is commonly stored in WordPress’s postmeta table. A scalar value is stored as a string. Arrays and objects accepted by metadata functions are serialized, so consumers must know the expected shape before reading them.
Best Value
For a single text field, a scalar key is usually easiest to query and migrate. For a group of related values, decide whether separate keys or one structured value gives the clearer schema. Document the key name, expected type, whether it is single or multiple, and what an empty value means.
Keep keys private when they are implementation details by using a leading underscore, but do not treat that convention as access control. Capability checks and correct REST settings determine who can change or receive the data.
Security and correctness checklist
- Create a nonce for the specific save action and verify it before processing input.
- Return during autosaves when the field should change only on an intentional edit.
- Return for revisions when a revision operation must not overwrite the current metadata.
- Check
current_user_can( 'edit_post', $post_id )or the post type’s appropriate capability. - Check that the expected field exists in
$_POSTbefore reading it. - Call
wp_unslash()before sanitizing submitted values. - Match the sanitizer to the field’s data type and rules.
- Escape every value for its output context when rendering.
- Prefix callbacks, nonce names, and keys to avoid collisions.
- Remember that
save_postmay run more than once and make the handler safe to repeat.
These checks protect both security and data integrity. Leaving out one can produce a box that appears to work while accepting unauthorized requests, storing unsafe content, or replacing valid data during an unrelated save.
Troubleshoot common failures
The box does not appear
- Confirm the screen argument exactly matches the post type slug.
- Check that the registration function is attached to
add_meta_boxesor the correct post-type-specific action. - Look in the editor’s screen options; an editor can hide individual boxes.
- Verify that the code is loaded in the active plugin or theme context.
The value never saves
- Inspect the nonce field name and action string on both sides of the verification call.
- Ensure the input’s
namematches the key tested in$_POST. - Check whether an autosave, revision, or failed capability check is causing an intentional early return.
- Confirm that the save callback is attached to
save_postand that the metadata key is the one you read later.
The saved text displays incorrectly
- Use
esc_textarea()inside a textarea, not an attribute or HTML escaping function intended for another context. - Use
esc_attr()for values placed in attributes andesc_html()for visible text. - Check that the sanitizer did not remove content your field actually needs; change the sanitizer rather than bypassing output escaping.
The REST API does not expose the value
- Register the key with
register_post_meta(). - Set
show_in_restappropriately and define the value’s type and cardinality. - Confirm that the post type supports
custom-fields.
Practical design examples
Short editorial flag
A checkbox or select value can live in a sidebar box. Store a constrained value, validate it against the allowed options, and keep the key separate from the post’s public content. This is a good classic-box use case when no live preview is needed.
Long internal note
A plain-text textarea belongs in the normal context so authors have enough width to write. Use the textarea sanitizer shown in the sample, escape with esc_textarea(), and decide whether clearing the note should delete the key or retain an empty value.
Structured details consumed by a block
When a block needs several related values, define a stable schema and register the metadata for REST use. A legacy box can remain as a fallback editor, but the block and server code must agree on field names, types, and whether each value is single or multiple.
Free tools Windows power users keep installed
One-click scans. No signup required.
Final implementation review
Before deploying, edit an existing item and verify that its current value is loaded, change it through the intended screen, and save normally. Then test an empty submission, an autosave, a revision, and a user who lacks the edit capability. Finally, check the stored key and, if applicable, the REST response. A meta box is complete only when its UI, validation, persistence, and editor integration all follow the same data contract.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




