Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Antihost offers managed WordPress hosting with free migration, one-click staging and a 14-day free trial.
A custom meta box is an editor panel that stores extra information about a WordPress post. The dependable implementation uses add_meta_box() on the add_meta_boxes hook, a render callback that loads and escapes the current value, and a save_post handler that verifies the request, sanitizes the field, and writes post metadata.
This guide shows a complete implementation for posts, explains how to target a custom post type, and covers what changes when the site uses the Block Editor or needs REST API access.
How a custom meta box works
WordPress stores post-specific key-value data as post metadata, commonly in the postmeta table. A meta box is the server-rendered user interface for editing one or more of those values in the post editor. It does not create a new database table by itself.
The flow has three distinct parts:
- Registration: an
add_meta_boxesaction callsadd_meta_box()and tells WordPress which screen, context, and priority to use. - Rendering: the callback receives the current
WP_Post, reads metadata withget_post_meta(), escapes it for the output context, and prints the controls plus a nonce. - Saving: a
save_postcallback validates the request, rejects autosaves or revisions when appropriate, checks the editor capability, sanitizes submitted data, and callsupdate_post_meta()or an intentional alternative.
WordPress documentation summarizes the registration step as using add_meta_box() with the add_meta_boxes action. The Block Editor continues to support most existing meta boxes, so this pattern remains suitable for many plugins and legacy integrations.
#1 Best Overall
- Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
- With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
- Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
- Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
- Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
Before you write the code
Put the feature in a plugin
Place the code in a site-specific plugin rather than a theme when the data should survive a theme change. A plugin also gives you a clear namespace for functions, nonce names, and metadata keys. The examples use the acme_ prefix; replace it with a prefix unique to your project.
Choose the field contract
Decide what the value means before choosing a control. A plain textarea, URL, number, date, checkbox, or structured array each needs different validation and sanitization. Decide whether an empty submission should delete the metadata key or deliberately store an empty value. Keep the key stable once content has been saved so future code and migrations can find it.
Complete example: a details textarea on posts
The following implementation adds an Extra details box to the normal edit screen for the built-in post post type. It uses a textarea called acme_details_field and stores the value under the protected-looking project key _acme_details. The underscore is only a naming convention; security comes from the save checks, not from the underscore.
<?php
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'
);
}
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
}
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 );
}
The code is intentionally small, but every line has a job. The registration hook makes the box appear, the render callback supplies the current value and a request-specific nonce, and the save callback refuses writes that do not represent an authorized edit.
Register the box on the correct screen
Screen argument
The fourth argument to add_meta_box() is the screen. Use post for standard posts, page for pages, or the registered slug of a custom post type. Other supported admin screens can also be targeted, but a post meta box must be attached to the screen whose object owns the metadata.
Context and priority
The fifth argument controls placement: normal places the panel in the main editing area, side places it in the sidebar, and advanced uses the additional editor area. The final argument is the priority, commonly high, default, low, or core. Priority influences ordering within a context; it does not replace the context choice.
Rank #2
- Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
- Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
- Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
- Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
- Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
Use a post-type-specific hook when appropriate
For a box that belongs to one post type, add_meta_boxes_{post_type} makes the intention explicit and avoids running registration code for unrelated screens. The general add_meta_boxes hook is useful when one callback registers boxes for several screens. WordPress runs these hooks after built-in boxes have been added, allowing your box to participate in the normal editor layout.
Render existing data safely
The render callback receives a WP_Post object. Read the current value with get_post_meta( $post->ID, $key, true ); the true argument requests one value instead of an array of matching values.
Escape for the exact HTML context at output time. Use esc_textarea() inside a textarea, esc_attr() inside an attribute, and esc_html() for visible text. Do not assume that a value is safe merely because it was previously saved by your code; metadata can be edited by other code, imports, or database tools.
Call wp_nonce_field() while rendering. Its action string and field name must match the values checked by the save handler. A nonce helps prove that the form submission came from the intended editing screen, but it is not a substitute for a capability check.
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 →Save only an authorized, intentional edit
The save_post action can run more than once during one update event. A robust callback therefore exits early unless all of the following conditions are met:
- The expected nonce field exists, is unslashed, and verifies against the action used when it was created.
- The request is not an automatic save when the handler is intended for an explicit edit.
- The post is not a revision when the value should belong to the original post.
- The current user has
current_user_can( 'edit_post', $post_id ), or the capability appropriate to the post type. - The expected form field exists before
$_POSTis read.
Use wp_unslash() before sanitizing submitted values. In the example, sanitize_textarea_field() removes invalid line content for a plain-text textarea, then update_post_meta() writes the normalized value. A field containing markup, a URL, or structured data needs a different sanitizer and validation policy; never apply a textarea sanitizer by habit.
Rank #3
- 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
- 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
- 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
- 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
- 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.
Restrict the handler to its post type
A nonce and capability check protect the request, but a shared save_post callback can still receive saves for other post types. If the plugin owns one custom post type, check get_post_type( $post_id ) and return for every other type. This prevents an identically named field from being interpreted on an unintended screen.
Choose empty-value behavior deliberately
The example always calls update_post_meta(), so an empty textarea becomes an empty stored value. If an empty submission should mean “no metadata,” call delete_post_meta() instead when the sanitized value is empty. Make the choice part of the field contract and keep it consistent with code that reads the key.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsAdd a meta box to a custom post type
Use the custom post type slug as the screen argument:
add_action( 'add_meta_boxes_book', 'acme_register_book_box' );
function acme_register_book_box() {
add_meta_box(
'acme_book_details',
__( 'Book details', 'acme' ),
'acme_render_book_box',
'book',
'side',
'default'
);
}
The post type can also supply a register_meta_box_cb option when it is registered. That callback is another place to register the box, while the save logic remains a separate action. Whichever registration method you choose, keep both registration and persistence restricted to the intended post type.
Confirm that the post type supports the editor features your workflow requires. In particular, REST-based metadata exposure depends on the post type supporting custom-fields when registered meta is used through the REST API.
Meta boxes in the Block Editor
The Block Editor supports most existing meta boxes for backward compatibility. A classic box is therefore a practical choice when a small server-rendered form is enough or when you are maintaining an established plugin.
PC 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 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchRank #4
- 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
- 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
- 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
- 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
- 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
There are trade-offs. A legacy box renders outside the block canvas and generally requires little JavaScript. A block or editor sidebar can provide live previews, richer controls, reusable components, and a more unified authoring experience, but it introduces JavaScript and build complexity. Decide based on the editing experience rather than assuming that every field should become a block.
| Requirement | Classic meta box | Block or sidebar approach |
|---|---|---|
| Small server-rendered form | Well suited | Usually unnecessary |
| Existing plugin compatibility | Strong backward compatibility | May require migration work |
| Live preview or interactive controls | Limited | Better fit |
| Reusable editor components | Not the primary model | Designed for this use |
| JavaScript and build requirements | Low for simple fields | Higher |
| REST API consumption | Requires registered meta separately | Typically uses registered data and editor APIs |
Register metadata for REST and block workflows
If a field must be edited by a block, read by a JavaScript sidebar, or consumed by a REST client, register it explicitly with register_post_meta() and set show_in_rest as required. Registration defines the key and its REST behavior; it does not replace the meta box render and save callbacks when you still provide a classic form.
add_action( 'init', 'acme_register_details_meta' );
function acme_register_details_meta() {
register_post_meta( 'post', '_acme_details', array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'sanitize_callback' => 'sanitize_textarea_field',
'auth_callback' => function( $allowed, $meta_key, $post_id ) {
return current_user_can( 'edit_post', $post_id );
},
) );
}
The post type must support custom-fields for registered metadata to be available through REST. For a custom post type, pass its slug instead of post and ensure that its supports configuration includes the feature. Keep the REST authorization and sanitization rules aligned with the rules used by the meta box save handler.
Store values predictably in post metadata
add_post_meta() accepts scalar, array, and object values. Scalar values are stored as strings; arrays and objects are serialized. That behavior makes metadata flexible, but it also makes a stable schema important.
- Choose a unique, prefixed key such as
_acme_detailsrather than a generic key likely to collide with another plugin. - Document whether the key is single-valued or can have multiple rows.
- Define the expected type, allowed range or format, and empty-value behavior.
- Keep the same schema for values written by the editor, imports, REST requests, and migrations.
Use get_post_meta() with the correct single or multiple-value expectation, and avoid silently changing a scalar key into an array without a migration plan.
Namespacing prevents collisions
Prefix function names, action callback names, nonce names, form field names, and metadata keys. A class or namespace is useful when a plugin has several boxes because it groups callbacks and reduces the chance that another plugin declares the same global function. The prefix should identify your project, not a generic word such as details or custom.
Best Value
- 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
- 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
- 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
- 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
- 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
Test the box before shipping
Editor checks
- Open a new and an existing item on the intended post type and confirm that the box appears in the selected context.
- Confirm that an existing value is loaded into the control and that the label is associated with the field.
- Save a normal edit, reload the screen, and verify that the value persists.
- Clear the field and verify the behavior you chose: an empty key or a deleted key.
- Check the same workflow in the Block Editor if that is part of the site.
Request and permission checks
- Submit the form without the nonce and confirm that no metadata is written.
- Use an invalid nonce and confirm that the handler returns before updating.
- Confirm that autosaves and revisions do not overwrite the canonical value when your workflow excludes them.
- Test with a user who cannot edit the post and verify that the value remains unchanged.
- Submit unexpected content and confirm that the stored value matches the sanitizer and validation rules for the field.
Multiple-save behavior
Logically compare the final metadata after an update that triggers more than one save_post call. The handler should be idempotent: processing the same valid value again must not create duplicate metadata rows or produce a different result.
Common failure modes and fixes
The box does not appear
Check that the registration callback is attached to add_meta_boxes or the correct post-type-specific hook, that the screen argument exactly matches the post type slug, and that the callback name is callable. Also check the editor screen’s Screen Options; users can hide meta boxes there.
Recommended Free Tools
The field displays but never saves
Inspect the form field name and compare it with the key read from $_POST. Then verify that the nonce field name and action match, the capability check passes, and the handler is not returning because the request is an autosave or revision. Finally, ensure that the callback is attached to save_post and that the value is not being overwritten by another save routine.
Values are corrupted or contain unwanted markup
Match sanitization to the field type and unslash the submitted value before sanitizing. Escape again when rendering. For structured values, validate the shape and each member against an allow-list instead of treating the entire payload as free-form text.
REST requests cannot see the field
Register the key with register_post_meta(), set show_in_rest appropriately, and confirm that the post type supports custom-fields. Also provide an authorization rule suitable for the post type; REST visibility does not automatically make a value writable by every user.
Quick Recap
Implementation checklist
- Register with
add_meta_box()from the appropriate meta-box hook. - Use a unique screen, callback, field, nonce, and metadata prefix.
- Load current data with
get_post_meta()and escape it for its HTML context. - Emit and verify a nonce tied to this field’s save action.
- Reject autosaves, revisions, unauthorized users, and missing fields when the workflow requires it.
- Unslash and sanitize according to the actual data type.
- Choose and document whether empty input deletes or stores the key.
- Restrict registration and saving to the intended post type.
- Register metadata for REST or block consumers and enable
custom-fieldssupport where required. - Test normal edits, repeated saves, permissions, autosaves, revisions, and malformed input.
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.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.

