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 minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallA custom meta box is a panel that appears in a WordPress edit screen and stores information about the post being edited. To build one, register the panel with add_meta_box() on the add_meta_boxes hook, render its controls in a callback, and process the submitted value in a guarded save_post handler.
Antihost offers managed WordPress hosting with free migration, one-click staging and a 14-day free trial.
The reliable pattern is small but strict: load and escape the existing value, print a field-specific nonce, reject autosaves and revisions when appropriate, verify the editor’s capability, unslash and sanitize the submitted value, then deliberately update or delete post metadata. The same approach works for built-in post types and custom post types, including sites that still use the Block Editor with legacy meta boxes.
As an Amazon Associate I earn from qualifying purchases.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →What a custom meta box does
WordPress post metadata is data attached to a post, page, or custom-post-type entry. A custom meta box supplies an editing interface for that data inside the post editor. Examples include a subtitle, an external video URL, a rating, a release date, a developer name, or a set of structured options that do not belong in the main post content.
The box itself does not store anything. add_meta_box() registers the panel, a render callback outputs its HTML, and a save callback decides whether and how the submitted value is persisted. In the common case, persistence uses get_post_meta() to read and update_post_meta() to write the value in the postmeta table.
#1 Best Overall
- BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
- EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
- COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
- LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
- WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.
Put the implementation in a plugin when the field belongs to the site’s editorial workflow or must survive a theme change. Theme code is appropriate only when the data is inseparable from that theme’s presentation and you accept losing the feature when the theme is replaced.
Plan the field before writing PHP
Choose the screen
The fourth argument to add_meta_box() identifies the screen. Use post for standard posts, page for pages, or the registered slug of a custom post type. WordPress also accepts other supported edit screens, but a box should be registered only where its data makes sense.
Choose the location and priority
The context controls placement: normal places the box in the main editor column, side places it in the sidebar, and advanced places it in the secondary area that may be collapsed. Priority controls its order relative to other boxes; default is a sensible starting point.
Define a stable key
Choose a unique, prefixed meta key such as _acme_details. The leading underscore commonly keeps the value out of the generic Custom Fields interface, while the project prefix prevents collisions with another plugin. Use the same prefix for callback names, nonce names, field names, and IDs.
Decide the value’s shape and empty-state behavior
Plain text, URLs, numbers, dates, booleans, arrays, and objects need different validation. Decide whether an empty submission should remain as an empty value or remove the key entirely. That decision affects queries, REST responses, and migration scripts, so encode it in the save handler rather than leaving it accidental.
Complete working example for a post
The following plugin-style example adds an Extra details textarea to posts. It uses a prefixed identifier, loads the current value, emits a nonce, and performs all standard save guards before writing sanitized text.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #2
- WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
- AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
- PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
- ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
- COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
<?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 );
}
1. Register the box on the correct hook
add_action( 'add_meta_boxes', ... ) runs after WordPress has prepared the edit screen’s built-in boxes. The callback calls add_meta_box() with six decisions: a unique ID, a translatable title, the render callback, the screen, the context, and the priority.
If the box belongs to only one post type, the more specific action is clearer: add_meta_boxes_book for a post type whose slug is book. It limits registration to that screen and makes the intent obvious when a plugin has several content types.
2. Render current data, not only an empty form
The render callback receives a WP_Post object. get_post_meta( $post->ID, '_acme_details', true ) retrieves the single current value. Escape at output time for the destination context: esc_textarea() for a textarea, esc_attr() for an attribute, and esc_html() for visible text.
wp_nonce_field() prints a hidden nonce pair into the box. The action string and field name are project-specific; they must match the values checked by the save handler.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →3. Treat the save callback as an untrusted request boundary
The save_post action can run more than once during one update event. The handler therefore returns early unless the request contains a valid nonce, is not an autosave, is not saving a revision, and comes from a user allowed to edit that post. Only after those checks should it read the field.
Submitted values in $_POST are slashed by WordPress. Call wp_unslash() before applying a sanitizer. For a plain textarea, sanitize_textarea_field() preserves line breaks while removing unsafe content. Finally, update_post_meta() writes the result and is safe to call repeatedly with the same value.
Rank #3
- Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
- Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
- Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
- ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
- Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
Adding a meta box to a custom post type
Use the post-type-specific action
Assume a custom post type with the slug game. Register its box on add_meta_boxes_game, then pass game as the screen argument:
add_action( 'add_meta_boxes_game', 'acme_register_game_box' );
function acme_register_game_box() {
add_meta_box(
'acme_game_details',
__( 'Game details', 'acme' ),
'acme_render_game_box',
'game',
'side',
'default'
);
}
Reuse the same nonce, capability, sanitization, and autosave protections in the save callback. Restrict that callback to the intended post type when one handler is attached globally:
if ( get_post_type( $post_id ) !== 'game' ) {
return;
}
That check prevents an identically named field submitted by another screen from being interpreted as game data.
Register through register_meta_box_cb
A custom post type can also declare a register_meta_box_cb callback in its registration arguments. WordPress invokes that callback while building the post-type edit screen. This is useful when the post type and its boxes are maintained together; the post-type-specific action is often easier to extend when several plugins may add boxes independently.
Confirm editor support
The post type must support the editor features your workflow expects. If the type does not expose an editor or does not have the relevant support flags, a correctly registered box may still appear in an unexpected editing experience. Test the actual edit screen for a new item, an existing item, a revision, and an autosave.
Meta boxes in the Block Editor
The Block Editor continues to support most existing legacy meta boxes. A server-rendered box can therefore be a practical choice for a small field, an established plugin, or a workflow that does not need live JavaScript interactions.
Rank #4
- Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
- Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
- 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
- Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
- USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
Compatibility does not mean that every box behaves like a native block sidebar. A legacy panel may appear below the block canvas or in a compatibility area, and its controls do not automatically participate in block previews. Decide based on the editorial experience you need rather than assuming that the older API is either unusable or equivalent to a block.
When a legacy box is the right fit
- A few scalar fields are enough and a server-rendered form meets the requirement.
- The plugin already uses a mature meta-box implementation and backward compatibility matters.
- The value is consumed on the server and does not need a live preview while blocks change.
When to build a block or editor sidebar instead
- Authors need interactive controls, immediate previews, repeatable rows, or rich media selection.
- The interface must behave like other React-based editor panels.
- Other clients need to read or write the value through the REST API.
| Approach | Editor integration | REST use | Implementation trade-off |
|---|---|---|---|
| Legacy PHP meta box | Backward-compatible panel in the editor | Requires deliberate meta registration for REST exposure | Small server-rendered implementation; less interactive |
| Block or editor sidebar | Native block-based authoring and live UI behavior | Usually designed around registered, REST-visible data | More JavaScript and build complexity |
| REST-enabled post meta | Storage layer rather than a visual panel | Available to REST clients when registered correctly | Requires schema, permissions, and post-type support decisions |
Registering meta for REST and editor clients
If a block, a sidebar, or an external client must access the value, register the meta explicitly with register_post_meta(). Set show_in_rest according to whether the value should be exposed, and describe the value with an appropriate type and single-versus-multiple setting.
add_action( 'init', 'acme_register_game_meta' );
function acme_register_game_meta() {
register_post_meta(
'game',
'_acme_score',
array(
'single' => true,
'type' => 'integer',
'show_in_rest' => true,
)
);
}
The post type also needs custom-fields support for registered meta to be available through REST. Treat REST exposure as an API decision: review the value’s schema, who may edit it, and whether exposing it publicly is appropriate. A private editorial note should not be made public merely because a client requests it.
Choose sanitization by field type
Plain text and multiline notes
Use sanitize_text_field() for a single-line value and sanitize_textarea_field() for plain multiline text. Escape with esc_html(), esc_attr(), or esc_textarea() when rendering.
Recommended Free Tools
URLs
Use esc_url_raw() or another URL-specific sanitizer before saving a URL, then esc_url() when outputting it as an HTML link. Decide whether only particular schemes such as HTTPS are acceptable; a generic text sanitizer is not a URL policy.
Numbers, dates, and enumerated choices
Convert a number to the expected numeric type and enforce its allowed range. For a select field, accept only values in a fixed allow-list. For dates, validate the format you intend to query and display instead of trusting a browser-supplied string.
Best Value
- Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
- Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
- Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
- Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
- Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
Checkboxes and missing fields
A checkbox is absent from $_POST when it is unchecked. Check for its presence and save an explicit false or zero, rather than returning early as though the request were incomplete. Hidden inputs can provide a submitted default, but the save handler should still validate the resulting value.
Arrays and objects
add_post_meta() and update_post_meta() accept scalar, array, and object values. Scalars are stored as strings; arrays and objects are serialized. Define a stable schema, validate each member, and consider whether a normalized set of individual keys would be easier to query than one serialized structure.
Security and correctness checklist
- Create a nonce for this box and verify the matching action before reading fields.
- Call
wp_unslash()before sanitizing submitted values. - Return during autosaves when the handler should process only intentional edits.
- Return for revisions unless the revision itself is deliberately part of your data workflow.
- Check
current_user_can( 'edit_post', $post_id ), or the capability appropriate to the post type. - Check that each expected field exists before accessing it, while accounting for controls such as unchecked checkboxes that are legitimately absent.
- Sanitize according to the field’s type, not with one universal sanitizer.
- Escape every value for its HTML output context.
- Prefix callback names, nonce names, input names, and meta keys.
- Keep the save operation idempotent because
save_postcan fire more than once for one update.
A nonce proves that the request came through a form generated for your action; it does not replace a capability check. Likewise, sanitizing output does not decide whether a user is allowed to change the post. Keep those responsibilities separate in the handler.
Decide whether to update or delete an empty value
The example always calls update_post_meta(), so clearing the textarea stores an empty string. Some projects prefer to remove the key when no value exists. That keeps a metadata query for existence meaningful and can reduce clutter, but code reading the value must then handle a missing key.
if ( $value === '' ) {
delete_post_meta( $post_id, '_acme_details' );
} else {
update_post_meta( $post_id, '_acme_details', $value );
}
Choose one convention and use it consistently across creation, editing, imports, REST updates, and migrations. Do not alternate between an empty string, null, and a deleted key without documenting the distinction.
Common failures and how to diagnose them
| Symptom | Likely cause | Fix |
|---|---|---|
| The box never appears | Wrong screen slug, callback not attached to the hook, or the box is placed in a collapsed context | Verify the post-type slug, use add_meta_boxes or the correct add_meta_boxes_{post_type} action, and check Screen Options and the chosen context. |
| The box appears on the wrong edit screen | The registration is attached globally without a screen restriction | Pass the intended screen to add_meta_box() or use the post-type-specific action. |
| The value displays but never changes | Missing field name, failed nonce, autosave/revision guard, capability failure, or an early return before the update | Inspect the rendered input name, confirm the nonce action and field name match, and test with a user who can edit the post. |
| HTML appears in a text field | Value was output without context-appropriate escaping | Use esc_textarea(), esc_attr(), or esc_html() at render time. |
| Unchecked state cannot be saved | The handler returns when the checkbox key is absent | Treat absence as the defined false value for that control, then sanitize and save it. |
| REST clients cannot see the value | Meta was not registered with show_in_rest, or the post type lacks custom-fields support |
Register the meta with an accurate type and enable the required post-type support, then review permissions. |
| Another plugin’s data changes unexpectedly | An unprefixed or generic meta key or function name collided | Rename identifiers with a project prefix and migrate the old key deliberately. |
Testing before release
- Create a new item as an authorized editor and confirm the box, label, default state, and nonce-bearing form appear.
- Save a normal value, reload the edit screen, and verify the exact value is rendered in the correct control.
- Clear the value and confirm the chosen empty-state behavior: an empty key or a deleted key.
- Edit the post as a user without the required capability and verify that the value is not changed.
- Trigger an autosave and inspect that the intentional value is not overwritten by an incomplete request.
- Update a revision and confirm the handler does not write revision data unless that is explicitly intended.
- Try malformed input for every field type, including an invalid URL, out-of-range number, unknown select option, and unexpected array member.
- Check the post type’s editor, REST response, and front-end output separately; a value can be stored correctly while being exposed or escaped incorrectly elsewhere.
Choosing the right implementation
Use a classic meta box when the requirement is a compact, server-rendered form and the data is primarily edited alongside the post. Move to a block or editor sidebar when authors need interactive previews or reusable editor components. Register post meta for REST when the value must be exchanged with blocks or other clients, regardless of whether a legacy box remains as one editing interface.
The APIs can coexist. A plugin may keep a legacy box for backward compatibility, register the same key for REST, and later add a block-based control. The important constraint is one stable schema and one clear permission model, so different interfaces do not sanitize or interpret the value differently.
Quick Recap
Final implementation checklist
- The box is registered with
add_meta_box()from the appropriate meta-box action. - The screen, context, and priority match the intended editorial workflow.
- The render callback loads existing metadata, escapes it for its HTML context, and prints a specific nonce.
- The save callback verifies that nonce, skips unwanted autosaves and revisions, checks capability, and confirms the field is present.
- Input is unslashed and sanitized according to its data type before persistence.
- Meta keys and callbacks use a unique project prefix.
- Empty submissions follow a documented update-or-delete policy.
- Custom post types use the correct screen hook and are protected from cross-type saves.
- REST consumers receive only deliberately registered metadata, with the post type supporting
custom-fields. - New saves, edits, unauthorized requests, autosaves, revisions, malformed values, and front-end output have all been tested.
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.




