To display a selected custom field in a WordPress theme, retrieve it with get_post_meta() in the template that renders the post, check whether it has a value, and output it using markup and escaping appropriate to that value. For new theme code, use this approach instead of the_meta(), which WordPress deprecated in version 6.0.2.
Choose the template for the view
Place the code in the theme file responsible for the screen where the metadata should appear. For one post, that is the relevant individual-post template; for metadata beside several posts, use the template or loop that renders that list. WordPress explains how template files control content display and how template tags retrieve database content for use in theme files.
Retrieve and display one field
Use the post ID and the field’s exact metadata key. With the third argument set to true, get_post_meta() returns one value; with false, it returns an array of values. When the requested key is missing on a valid post, the result is an empty string or empty array, respectively. Non-serialized scalar values are returned as strings, so do not assume a number stored in metadata will arrive as a PHP number. See the get_post_meta() reference.
<?php
$subtitle = get_post_meta( get_the_ID(), 'subtitle', true );
if ( '' !== $subtitle ) {
echo '<p class="post-subtitle">' . esc_html( $subtitle ) . '</p>';
}
?>
This example treats subtitle as plain text, avoids output when the value is empty, and escapes it for an HTML text node. Choose markup and escaping to match the actual value and its output context; plain text, a URL, and an HTML attribute do not share the same escaping requirements.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errors#1 Best Overall
Use a selected-field approach, not the_meta()
the_meta() automatically outputs a list of eligible custom fields and omits protected metadata. That gives a theme less control over which fields appear and how each is presented. WordPress marks the function deprecated since version 6.0.2 and recommends retrieving fields with get_post_meta() for manual rendering. The post metadata rendering handbook also documents functions used to retrieve and render metadata.
Understand underscore-prefixed keys
Keys beginning with an underscore are treated as protected: they are omitted by the_meta() and do not appear in WordPress’s built-in Custom Fields editing screen. Their absence from those built-in displays does not mean a theme cannot deliberately retrieve a value when it knows the key. WordPress describes these behaviors in its references for managing post metadata and post template files. The editor interface’s display can also depend on the field type and site setup.
Quick Recap
Best Value
Rank #4
- Used Book in Good Condition
Rank #3
Rank #2
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.

