WordPress Custom Fields(Custom Fields) allows you to add additional information to an article or page, such as price, subtitle, source link, and so on. However, after adding the fields, many users are not sure how to display these contents on the front-end page.
This tutorial will take you step-by-step through the use of the WPCode plugin to create a simple code snippet that calls and displays the value of a custom field on the front-end. There is no need to modify the theme files and it is simple enough for users who are just getting started.
![Image [1] - Calling custom fields with WPCode: a quick way for newbies to display additional information about a post](http://gqxi.cn/wp-content/uploads/2025/06/20250627134718725-image.png)
I. Preparation: adding custom fields
Before calling it, you need to add the article to theCustom FieldsThe
The steps to add are as follows:
- Open the WordPress backend and edit any post
- Click on the "three-dot menu" in the upper right corner → select "Preferences".
![Image [2] - Calling custom fields with WPCode: a quick way for newbies to display additional information about a post](http://gqxi.cn/wp-content/uploads/2025/06/20250627134908863-image.png)
- Check "Customize Fields" in the Panel
![Image [3] - Calling custom fields with WPCode: a quick way for newbies to display additional information about a post](http://gqxi.cn/wp-content/uploads/2025/06/20250627134944272-image.png)
- At the bottom of the page, the "Custom Fields" module will appear, click "Add New Field".
![Image [4] - Calling custom fields with WPCode: a quick way for newbies to display additional information about a post](http://gqxi.cn/wp-content/uploads/2025/06/20250627135003704-image.png)
- Enter the field name and field value, for example:
- Field Name:
subtitle
- field value:
This is an article about traveling
- Field Name:
Click "Update" to save the article.
Install and activate the WPCode plug-in.
- Go to Backstage → Plugins → Install Plugin
![Image [5] - Calling custom fields with WPCode: a quick way for newbies to display additional information about a post](http://gqxi.cn/wp-content/uploads/2025/06/20250627135857329-image.png)
- Search "WPCode"
![Image [6] - Calling custom fields with WPCode: quick display of additional information on articles for newbies](http://gqxi.cn/wp-content/uploads/2025/06/20250627135949734-image.png)
- Click "Install" and then "Enable".
WPCode is a plugin that centralizes the management of code snippets, replacing direct editing of thethematicCode for more security and convenience.
Creating a new PHP code snippet
- Open in the backend navigation: WPCode → Code Snippets → Add New
![Image [7] - Calling custom fields with WPCode: quick display of additional information on articles for newbies](http://gqxi.cn/wp-content/uploads/2025/06/20250627140121240-image.png)
- Click on "PHP Snippet" to go tocodingEdit page
![Image [8] - Calling custom fields with WPCode: a quick way for newbies to display additional information about a post](http://gqxi.cn/wp-content/uploads/2025/06/20250627140206683-image.png)
- existcaptionFill in the blanks:
Display Custom Field on Frontend
![Image [9] - Calling custom fields with WPCode: a quick way for newbies to display additional information about a post](http://gqxi.cn/wp-content/uploads/2025/06/20250627140237947-image.png)
Enter the following in the code box:
add_filter( 'the_content', 'add_custom_field_to_content' );
function add_custom_field_to_content( $content ) {
if ( is_singular( 'post' ) ) {
$subtitle = get_post_meta( get_the_ID(), 'subtitle', true );
if ( $subtitle ) {
$custom_output = '<p style="font-style: italic; color: #555;">Subtitle:' . esc_html( $subtitle ) . '</p>';
$content = $custom_output . $content.
}
}
return $content.
}
This code will insert asubheadingparagraph, the field name is subtitle
The
- In the "Insertion" section choose: Auto Insert → Run Everywhere
![Image [10] - Calling custom fields with WPCode: a quick way for newbies to display additional information about a post](http://gqxi.cn/wp-content/uploads/2025/06/20250627140425836-image.png)
- Click "Activate" → "Save Snippet" in the upper right corner to save and enable it.
![Image [11] - Calling custom fields with WPCode: a quick way for newbies to display additional information about a post](http://gqxi.cn/wp-content/uploads/2025/06/20250627140526686-image.png)
Fourth, the foreground to view the effect
Open the file you added subtitle
field of that article, refresh the page.
You'll see the content at the top of the body:
Subtitle: this is an article about traveling
Indicates that the code successfully reads and outputs the custom field content.
V. Extended application: support for multiple fields
If you have multiple fields, such as price
,author_note
etc., can also be output uniformly in a single code snippet:
add_filter( 'the_content', 'add_multiple_fields_to_content' );
function add_multiple_fields_to_content( $content ) {
if ( is_singular( 'post' ) ) {
$subtitle = get_post_meta( get_the_ID(), 'subtitle', true );
$price = get_post_meta( get_the_ID(), 'price', true );;
$note = get_post_meta( get_the_ID(), 'author_note', true );
$output = '';
if ( $subtitle ) {
$output . = '<p><strong>Subtitle:</strong> ' . esc_html( $subtitle ) . '</p>';
}
if ( $price ) {
$output . = '<p><strong>Price:</strong> ' . esc_html( $price ) . '</p>';
}
if ( $note ) {
$output . = '<p><strong>Author's Notes:</strong> ' . esc_html( $note ) . '</p>';
}
$content = $output . $content;
}
return $content; }
}
concluding remarks
Using the WPCode plug-in makes it easier to make the WordPress The site displays custom field content without changing the template. Just add a simple paragraph PHP code, you can output this additional information on the article page.
This approach is good for beginners to understand the structure of WordPress content and also lays the groundwork for future page personalization. If you want to display fields in other locations, such as above headings, at the end of posts, or in the sidebar, you can continue to use shortcodes or other hooks to achieve this, so feel free to explore further.
Link to this article:http://gqxi.cn/en/63738The article is copyrighted and must be reproduced with attribution.
No comments