Once ACF has saved your fields, you still need a template or a component to render them. This lesson uses the product field group from Part 1. Work on a test site where you can upload files through your hosting file manager or SFTP and activate plugins in WordPress.
1. Choose a rendering approach
A custom shortcode gives you a portable component for post content in both the block and classic editors. Some page builders can bind directly to ACF fields. If every product should use the same layout, Part 3 shows where the component belongs in a single-product template.
get_field() returns a value for your code to check, format, and escape. the_field() prints its output directly. The example passes the post ID to get_field() to make the data source explicit. It registers its own shortcode, [bwp_product_specs]. ACF’s built-in [acf] shortcode has been disabled by default on new installs since version 6.3. get_field() reference · ACF shortcode documentation
2. Create the specifications plugin
- In
wp-content/plugins/, create a folder namedbwp-product-specs. - Create a plain-text file called
bwp-product-specs.phpinside that folder. Paste the complete example into the file and save it in UTF-8. Check that your editor kept the.phpextension. - Go to Plugins → Installed Plugins and activate BWP Product Specs. Because this is a plugin, you can switch themes without moving the shortcode code.
<?php
/**
* Plugin Name: BWP Product Specs
* Description: Displays public ACF product specifications with a shortcode.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
function bwp_render_product_specs() {
$post_id = get_the_ID();
if ( ! $post_id || ! function_exists( 'get_field' ) ) {
return '';
}
if ( post_password_required( $post_id ) ) {
return '';
}
$model = (string) get_field( 'product_model', $post_id );
$material = (string) get_field( 'product_material', $post_id );
$moq = (int) get_field( 'product_moq', $post_id );
$photo_id = get_field( 'product_photo', $post_id );
$file_url = get_field( 'product_datasheet', $post_id );
$datasheet = is_string( $file_url ) ? esc_url( $file_url ) : '';
$photo = is_numeric( $photo_id ) && (int) $photo_id > 0
? wp_get_attachment_image( (int) $photo_id, 'large' )
: '';
$specs = array(
'Model number' => $model,
'Material' => $material,
'Minimum order quantity' => $moq > 0 ? $moq . ' units' : '',
);
$rows = '';
foreach ( $specs as $label => $value ) {
if ( '' === trim( $value ) ) {
continue;
}
$rows .= '<dt>' . esc_html( $label ) . '</dt>';
$rows .= '<dd>' . esc_html( $value ) . '</dd>';
}
if ( '' === $rows && ! $photo && '' === $datasheet ) {
return '';
}
$html = '<section class="bwp-product-specs"><h2>Product specifications</h2>';
$html .= $photo;
if ( '' !== $rows ) {
$html .= '<dl>' . $rows . '</dl>';
}
if ( '' !== $datasheet ) {
$html .= '<p><a href="' . $datasheet . '">View datasheet (PDF)</a></p>';
}
return $html . '</section>';
}
add_shortcode( 'bwp_product_specs', 'bwp_render_product_specs' );
The callback reads five named fields from the current post. It escapes plain text with esc_html() and the PDF URL with esc_url(). The image ID goes to wp_get_attachment_image(), which builds the image markup. The callback returns the completed HTML for WordPress to insert. WordPress Shortcode API · wp_get_attachment_image() reference
3. Insert the shortcode and preview the post
- Open the test post from Part 1. Add a Shortcode block below the product description. In the classic editor, add the shortcode on its own line.
- Enter
[bwp_product_specs], save the draft, and open its preview. - Look for Product specifications,
FC-304-50,304 stainless steel,50 units, the photo, and View datasheet (PDF). Open the PDF to confirm the link points to the intended version. - Clear one optional field and preview again. Its output should disappear while the remaining specifications stay visible.
Troubleshoot fields that don’t appear
- The page prints [bwp_product_specs] as plain text.
- Check that the plugin is active, the tag is spelled correctly, and the block or builder widget processes shortcodes.
- The entire section is empty.
- Confirm that ACF is active and the current post has saved values under the expected field names. Inside a query loop, verify that WordPress is passing the ID of the product you intend to display.
- Text appears, but the photo or PDF is missing.
- Check that the image field returns an Image ID and the file field returns a File URL. Confirm that both files still exist in the Media Library. Open the PDF in a signed-out window to check visitor access.
- The public page still shows an old value.
- Save the post and reload it in a signed-out window. If it still shows the old value, clear the affected page or CDN cache according to your site’s setup.