Single-line text
String<?php echo esc_html( CFS()->get( 'text' ) ); ?>Output reference
This document provides output references for Custom Field Suite (CFS) and for features added by atshift Fields. The examples use field_name as a placeholder; replace it with your actual field name and escape all values according to their output context.
Text and values
Replace the orange text with the field name you configured. Green text indicates escaping functions.
<?php echo esc_html( CFS()->get( 'text' ) ); ?><?php
$value = CFS()->get( 'textarea' );
echo nl2br( esc_html( $value ) );
?>This example preserves line breaks when rendering plain text.
<?php echo wp_kses_post( CFS()->get( 'wysiwyg' ) ); ?>Display the phone number only
<?php echo esc_html( CFS()->get( 'phone' ) ); ?>Display as a phone link
<?php $phone = CFS()->get( 'phone' ); ?>
<a href="tel:<?php echo esc_attr( $phone ); ?>">
<?php echo esc_html( $phone ); ?>
</a>Display the email address only
<?php echo esc_html( antispambot( CFS()->get( 'email' ) ) ); ?>Display as an email link
<?php $email = CFS()->get( 'email' ); ?>
<a href="mailto:<?php echo esc_attr( antispambot( $email ) ); ?>">
<?php echo esc_html( antispambot( $email ) ); ?>
</a><?php $url = CFS()->get( 'url' ); ?>
<a href="<?php echo esc_url( $url ); ?>">Visit link</a><?php echo esc_html( CFS()->get( 'number' ) ); ?>Display the stored format
<?php echo esc_html( CFS()->get( 'date' ) ); ?>Include the weekday
<?php
$date = CFS()->get( 'date' );
if ( $date ) {
echo esc_html( wp_date( 'F j, Y (D)', strtotime( $date ) ) );
}
?>wp_date() localizes the weekday for the WordPress site language. Adjust parsing to match the field's stored format.
24-hour format
<?php
$time = CFS()->get( 'time' );
if ( $time ) {
echo esc_html( wp_date( 'H:i', strtotime( $time ) ) );
}
?>12-hour AM / PM format
<?php
$time = CFS()->get( 'time' );
if ( $time ) {
echo esc_html( wp_date( 'g:i A', strtotime( $time ) ) );
}
?><?php $color = sanitize_hex_color( CFS()->get( 'color' ) ); ?>
<span style="color:<?php echo esc_attr( $color ); ?>">Colored text</span>Choices
Replace the orange text with the field name you configured. Green text indicates escaping functions.
<?php foreach ( (array) CFS()->get( 'select' ) as $value ) : ?>
<span><?php echo esc_html( $value ); ?></span>
<?php endforeach; ?>The field returns an array even when configured for a single selection.
<ul>
<?php foreach ( (array) CFS()->get( 'checkbox' ) as $value ) : ?>
<li><?php echo esc_html( $value ); ?></li>
<?php endforeach; ?>
</ul><?php echo esc_html( CFS()->get( 'radio' ) ); ?><?php if ( CFS()->get( 'true_false' ) ) : ?>
<span>Enabled</span>
<?php endif; ?><?php
$choice = CFS()->get( 'conditional_choice' );
?>
<?php if ( 'select1' === $choice ) : ?>
<div>
<p><?php echo esc_html( CFS()->get( 'field1' ) ); ?></p>
<p><?php echo esc_html( CFS()->get( 'field2' ) ); ?></p>
</div>
<?php elseif ( 'select2' === $choice ) : ?>
<div>
<p><?php echo esc_html( CFS()->get( 'field3' ) ); ?></p>
<p><?php echo esc_html( CFS()->get( 'field4' ) ); ?></p>
</div>
<?php endif; ?>Retrieve the current selection using the Conditional Group's field name, then output the matching child fields. You can freely add HTML such as headings, images, and paragraphs between the PHP tags. Hidden branch values are retained, so do not output child fields without checking the selected value.
Links and media
Replace the orange text with the field name you configured. Green text indicates escaping functions.
<?php
$link = CFS()->get( 'hyperlink' ); // PHP Array setting
if ( ! empty( $link['url'] ) ) :
?>
<a href="<?php echo esc_url( $link['url'] ); ?>"
target="<?php echo esc_attr( $link['target'] ?? '_self' ); ?>">
<?php echo esc_html( $link['text'] ?: $link['url'] ); ?>
</a>
<?php endif; ?>The HTML setting returns ready-made link markup. PHP Array is recommended when you need full output control.
<?php $file_url = CFS()->get( 'file' ); ?>
<a href="<?php echo esc_url( $file_url ); ?>">Download</a><?php
$attachment_id = (int) CFS()->get( 'file' );
echo wp_get_attachment_image( $attachment_id, 'large' );
?>The returned value changes between a URL and an ID according to the field's Return Value setting.
<?php
// Set the HTML tags and attributes that wp_kses() may output.
// true allows the specified attribute.
$allowed = array(
'div' => array( 'class' => true ), // Allow div and its class attribute
'span' => array( 'class' => true ), // Allow span and its class attribute
'pre' => array(), // Allow pre without attributes
'code' => array( 'class' => true ), // Allow code and its class attribute
'button' => array( // Allow button with the attributes below
'type' => true, 'class' => true, // type and class attributes
'data-label' => true, 'data-copied' => true, // data attributes
),
);
echo wp_kses( CFS()->get( 'code_view' ), $allowed );
?>Repeating values
Replace the orange text with the field name you configured. Green text indicates escaping functions.
<?php foreach ( (array) CFS()->get( 'items' ) as $row ) : ?>
<article>
<h3><?php echo esc_html( $row['title'] ?? '' ); ?></h3>
<p><?php echo nl2br( esc_html( $row['description'] ?? '' ) ); ?></p>
</article>
<?php endforeach; ?>Each row is an array keyed by its subfield names. Escape every subfield according to its type.
<?php foreach ( (array) CFS()->get( 'sections' ) as $section ) : ?>
<section>
<h2><?php echo esc_html( $section['heading'] ?? '' ); ?></h2>
<ul>
<?php foreach ( (array) ( $section['items'] ?? array() ) as $item ) : ?>
<li>
<strong><?php echo esc_html( $item['title'] ?? '' ); ?></strong>
<p><?php echo nl2br( esc_html( $item['description'] ?? '' ) ); ?></p>
</li>
<?php endforeach; ?>
</ul>
</section>
<?php endforeach; ?>sections is the parent loop and items is the child loop. Read the child loop from the parent row array rather than calling CFS()->get() again.
WordPress native
<?php
$terms = get_the_terms( get_the_ID(), 'category' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) echo esc_html( $term->name );
}
?><?php
$terms = get_the_terms( get_the_ID(), 'post_tag' );
if ( $terms && ! is_wp_error( $terms ) ) {
foreach ( $terms as $term ) echo esc_html( $term->name );
}
?><?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'large' );
}
?>These fields store WordPress-native data, so you can render them with standard WordPress template functions.
Values from another post
Replace the orange text with the field name or post type you configured. Green text indicates escaping functions.
<?php
$post_id = 123;
echo esc_html( CFS()->get( 'field_name', $post_id ) );
?>Pass a post ID as the second argument of CFS()->get() to retrieve a field from any post, page, or custom post type, regardless of the currently displayed post.
<?php
$post_ids = get_posts( array(
'post_type' => 'news', // Specify post or a custom post type
'posts_per_page' => 1,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'fields' => 'ids',
) );
if ( $post_ids ) :
$post_id = (int) $post_ids[0];
?>
<h4><?php echo esc_html(
CFS()->get( 'text', $post_id )
); ?></h4>
<p><?php echo nl2br( esc_html(
CFS()->get( 'textarea', $post_id )
) ); ?></p>
<?php else : ?>
<p>No data found.</p>
<?php endif; ?>setup_postdata() and wp_reset_postdata() are not needed when you only retrieve CFS values by post ID. Use a standard WordPress loop when you also need template tags such as the post title.
Layout only
These fields organize inputs in the WordPress admin. They do not store values themselves. Retrieve each field placed inside them by its own field name. Conditional Groups store their selected value; see the choice fields section above.