Mohamed Sharaf

WordPress custom fields: what they are and how to show them

Store extra details on a post, like a rating or a price, and display them in your theme.

· 1 min read

From the archive: first published on mohamedsharaf.net in November 2010. Rewritten and checked in 2026; some details may be out of date.

Custom fields let you attach extra pieces of information to a post: a product price, a book rating, a “mood” line. Each field is a simple pair: a key and a value.

1. Add a field

In the post editor, open the Custom Fields panel (in the block editor, enable it from Preferences → Panels). Add a key, such as rating, and a value, such as 4.5.

2. Show it in your theme

Inside the loop of your template (for example single.php):

<?php $rating = get_post_meta( get_the_ID(), 'rating', true ); ?>
<?php if ( $rating ) : ?>
  <p class="rating">Rating: <?php echo esc_html( $rating ); ?></p>
<?php endif; ?>

The third argument, true, returns a single value instead of an array. Always escape the output with esc_html(): custom fields are content, and content can contain anything.

ShareWhatsAppLinkedInXTelegramFacebook