Text and values

Text and value fields

Replace the orange text with the field name you configured. Green text indicates escaping functions.

Single-line text

String
<?php echo esc_html( CFS()->get( 'text' ) ); ?>

Textarea

String

Safe plain-text display

<?php
$value = CFS()->get( 'textarea' );
echo nl2br( esc_html( $value ) );
?>

This example preserves line breaks and safely renders any entered HTML tags as text.

Display links and permitted HTML

<?php
$value = CFS()->get( 'textarea' );
echo wp_kses_post( wpautop( $value ) );
?>

This example allows links and other permitted HTML entered in the textarea. Use a custom wp_kses() allowlist if you need stricter control.

WYSIWYG editor

HTML string
<?php echo wp_kses_post( CFS()->get( 'wysiwyg' ) ); ?>

The WYSIWYG editor returns an HTML string intended for body content. Use wp_kses_post() when you want to keep common post-content HTML such as links, paragraphs, and lists. If you need the same processing as normal post content, such as shortcodes or embeds, use apply_filters( 'the_content', CFS()->get( 'wysiwyg' ) ) after confirming that behavior is appropriate for the field.

Phone number

String

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>

Email address

String

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>

URL

String

Display as a normal link

<?php $url = CFS()->get( 'url' ); ?>
<a href="<?php echo esc_url( $url ); ?>">Visit link</a>

Detect social URLs and display an icon link

<?php
$url = CFS()->get( 'url' );

// Inspect the URL host and switch the icon and label.
// icon_class uses Font Awesome as an example. You can replace it with SVG or image icons.
$host       = strtolower( (string) wp_parse_url( $url, PHP_URL_HOST ) );
$host       = preg_replace( '/^www\./', '', $host );
$service    = 'website';
$icon_class = 'fa-solid fa-link';
$label      = 'Website';

if ( false !== strpos( $host, 'instagram.com' ) ) {
  $service    = 'instagram';
  $icon_class = 'fa-brands fa-instagram';
  $label      = 'Instagram';
} elseif ( false !== strpos( $host, 'x.com' ) || false !== strpos( $host, 'twitter.com' ) ) {
  $service    = 'x';
  $icon_class = 'fa-brands fa-x-twitter';
  $label      = 'X';
} elseif ( false !== strpos( $host, 'facebook.com' ) ) {
  $service    = 'facebook';
  $icon_class = 'fa-brands fa-facebook-f';
  $label      = 'Facebook';
} elseif ( false !== strpos( $host, 'youtube.com' ) || false !== strpos( $host, 'youtu.be' ) ) {
  $service    = 'youtube';
  $icon_class = 'fa-brands fa-youtube';
  $label      = 'YouTube';
} elseif ( false !== strpos( $host, 'line.me' ) || false !== strpos( $host, 'lin.ee' ) ) {
  $service    = 'line';
  $icon_class = 'fa-brands fa-line';
  $label      = 'LINE';
}

if ( $url ) :
?>
  <a class="social-link social-link--<?php echo esc_attr( $service ); ?>"
     href="<?php echo esc_url( $url ); ?>"
     target="_blank"
     rel="noopener">
    <i class="<?php echo esc_attr( $icon_class ); ?>" aria-hidden="true"></i>
    <span><?php echo esc_html( $label ); ?></span>
  </a>
<?php endif; ?>

The URL field returns the stored URL string. By checking the domain at output time, you can switch icons and CSS classes for social links.

Number

String

Display the number only

<?php echo esc_html( CFS()->get( 'number' ) ); ?>

Display with a unit such as kg

<?php
$weight = CFS()->get( 'weight' );

// Do not use empty() here, because 0 can be a valid value.
if ( null !== $weight && '' !== (string) $weight ) :
?>
  <span class="measurement">
    <span class="measurement-value"><?php echo esc_html( number_format_i18n( (float) $weight, 1 ) ); ?></span>
    <span class="measurement-unit">kg</span>
  </span>
<?php endif; ?>

Keep the stored field value numeric and add units in the template. This keeps the value usable for calculations and sorting.

Date

String

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.

Time

String

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 ) ) );
}
?>

Color

String
<?php $color = sanitize_hex_color( CFS()->get( 'color' ) ); ?>
<span style="color:<?php echo esc_attr( $color ); ?>">Colored text</span>

Choices

Choice fields

Replace the orange text with the field name you configured. Green text indicates escaping functions.

Select (dropdown menu)

Array
<?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.

Checkbox

Array
<ul>
<?php foreach ( (array) CFS()->get( 'checkbox' ) as $value ) : ?>
  <li><?php echo esc_html( $value ); ?></li>
<?php endforeach; ?>
</ul>

Radio buttons

String
<?php echo esc_html( CFS()->get( 'radio' ) ); ?>

True / False (simple checkbox)

Boolean-like value
<?php if ( CFS()->get( 'true_false' ) ) : ?>
  <span>Enabled</span>
<?php endif; ?>

Conditional Group

Selected value string
<?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

Links, files, and embeds

Replace the orange text with the field name you configured. Green text indicates escaping functions.

File (return URL)

URL string
<?php $file_url = CFS()->get( 'file' ); ?>
<a href="<?php echo esc_url( $file_url ); ?>">Download</a>

When returning a URL, you can still use wp_check_filetype() to infer the extension and MIME type. Choose the ID return value when you need more reliable attachment metadata.

File (return ID)

Attachment ID
<?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.

File (show icons by file type)

Attachment ID
<?php
// Set the File field's Return Value to Attachment ID.
$attachment_id = (int) CFS()->get( 'file' );
$file_url      = wp_get_attachment_url( $attachment_id );
$mime_type     = get_post_mime_type( $attachment_id );
$file_type     = wp_check_filetype( $file_url );
$extension     = strtolower( $file_type['ext'] ?? '' );
$label         = get_the_title( $attachment_id ) ?: basename( (string) $file_url );

// Default values for files that do not match a more specific type.
$icon_label    = 'FILE';
$icon_class    = 'file';

// Switch the display label and CSS class by extension or MIME type.
if ( 'pdf' === $extension ) {
  $icon_label = 'PDF';
  $icon_class = 'pdf';
} elseif ( 0 === strpos( (string) $mime_type, 'image/' ) ) {
  $icon_label = 'IMG';
  $icon_class = 'image';
} elseif ( 0 === strpos( (string) $mime_type, 'audio/' ) ) {
  $icon_label = 'AUDIO';
  $icon_class = 'audio';
} elseif ( 0 === strpos( (string) $mime_type, 'video/' ) ) {
  $icon_label = 'VIDEO';
  $icon_class = 'video';
} elseif ( in_array( $extension, array( 'zip', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx' ), true ) ) {
  $icon_label = strtoupper( $extension );
  $icon_class = $extension;
}

if ( $file_url ) :
?>
  <!-- These data attributes make the file type available to theme CSS and JavaScript. -->
  <a class="download-link download-link--<?php echo esc_attr( $extension ); ?>"
     href="<?php echo esc_url( $file_url ); ?>"
     data-file-ext="<?php echo esc_attr( $extension ); ?>"
     data-file-mime="<?php echo esc_attr( $mime_type ); ?>">
    <!-- Replace this span with your site's SVG, icon font, or component markup. -->
    <span class="file-icon file-icon--<?php echo esc_attr( $icon_class ); ?>" aria-hidden="true">
      <?php echo esc_html( $icon_label ); ?>
    </span>
    <span><?php echo esc_html( $label ); ?></span>
  </a>
<?php endif; ?>

This example branches by PDF, image, audio, video, Office files, and other files, then changes the label and CSS class by type. Outputting data-file-ext and data-file-mime also makes file types easy to handle from theme CSS or JavaScript.

Code View

HTML string
<?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 );
?>

Shortcode

Rendered HTML

Display the rendered shortcode output

<?php echo CFS()->get( 'form_shortcode' ); ?>

Inspect the saved shortcode text

<?php
$shortcode = CFS()->get( 'form_shortcode', false, array( 'format' => 'raw' ) );
echo esc_html( $shortcode );
?>

CFS()->get() returns the rendered result of the saved shortcode. Role controls for the Shortcode field only determine whether the input field is shown in the post editing screen; they do not require that role when a saved value is rendered in a theme. Limit this field to trusted shortcodes and adjust escaping in the shortcode itself or with wp_kses() when needed.

Embed Code

iframe HTML

Display an allowed iframe embed

<?php
// The Embed Code field keeps only iframes from allowed providers when saving.
// At output time, allow only the iframe tag and the attributes needed for embeds.
$allowed = array(
  'iframe' => array(
    'src'             => true,
    'width'           => true,
    'height'          => true,
    'title'           => true,
    'class'           => true,
    'style'           => true,
    'loading'         => true,
    'allow'           => true,
    'allowfullscreen' => true,
    'frameborder'     => true,
    'referrerpolicy'  => true,
    'aria-label'      => true,
  ),
);

echo wp_kses( CFS()->get( 'embed_code' ), $allowed );
?>

Use this field for iframe embeds from providers allowed in the field settings, such as Google Maps, YouTube, Vimeo, OpenStreetMap, Google Calendar, Google Forms, Spotify, and SoundCloud. Script-based embed code is not supported.

Repeating values

Loops

Replace the orange text with the field name you configured. Green text indicates escaping functions.

Loop (repeating fields)

Array of rows
<?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.

Nested loop (repeating fields)

Array inside each row
<?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

WordPress-native data

Post Categories (Standard / Global)

Terms

Display standard category names

<?php
$terms = get_the_terms( get_the_ID(), 'category' );
if ( $terms && ! is_wp_error( $terms ) ) {
  foreach ( $terms as $term ) echo esc_html( $term->name );
}
?>

Display standard categories as links

<?php
$terms = get_the_terms( get_the_ID(), 'category' );
if ( $terms && ! is_wp_error( $terms ) ) {
  foreach ( $terms as $term ) {
    $url = get_term_link( $term );
    if ( ! is_wp_error( $url ) ) {
      echo '<a href="' . esc_url( $url ) . '">' . esc_html( $term->name ) . '</a>';
    }
  }
}
?>

Display Shared Taxonomy names

<?php
$terms = get_the_terms( get_the_ID(), 'global_category' ); // Replace with your taxonomy name
if ( $terms && ! is_wp_error( $terms ) ) {
  foreach ( $terms as $term ) echo esc_html( $term->name );
}
?>

Display Shared Taxonomy terms as links

<?php
$terms = get_the_terms( get_the_ID(), 'global_category' ); // Replace with your taxonomy name
if ( $terms && ! is_wp_error( $terms ) ) {
  foreach ( $terms as $term ) {
    $url = get_term_link( $term );
    if ( ! is_wp_error( $url ) ) {
      echo '<a href="' . esc_url( $url ) . '">' . esc_html( $term->name ) . '</a>';
    }
  }
}
?>

Post Categories (Standard / Global) stores WordPress terms in the selected taxonomy rather than CFS-specific post meta. In themes, render the value with standard WordPress template functions such as get_the_terms().

Post Tags (Native)

Terms

Display tag names

<?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 );
}
?>

Display tags as links

<?php
$terms = get_the_terms( get_the_ID(), 'post_tag' );
if ( $terms && ! is_wp_error( $terms ) ) {
  foreach ( $terms as $term ) {
    $url = get_term_link( $term );
    if ( ! is_wp_error( $url ) ) {
      echo '<a href="' . esc_url( $url ) . '">' . esc_html( $term->name ) . '</a>';
    }
  }
}
?>

Post Title (Native)

WordPress native
<?php
echo esc_html( get_the_title() );
?>

Post Title (Native) updates the native WordPress post title rather than CFS-specific post meta. In themes, render it with standard template functions such as get_the_title().

Post Content (Native)

WordPress native
<?php
the_content();
?>

Post Content (Native) updates native post_content. It is not CFS-specific post meta, so themes should render it with WordPress content functions such as the_content() or get_the_content().

Save / Publish (Native)

WordPress native
<?php
$status = get_post_status();
$status_object = get_post_status_object( $status );
echo esc_html( $status_object->label ?? $status );
echo esc_html( get_the_date( 'Y-m-d H:i' ) );
?>

Save / Publish (Native) updates native WordPress status, visibility, publish date, and related save action data. It does not produce a CFS field value to output; use functions such as get_post_status() and get_the_date() when needed.

Values from another post

Retrieve values outside the current post

Replace the orange text with the field name or post type you configured. Green text indicates escaping functions.

Retrieve by post ID

Post ID
<?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.

Query and display one custom post

Custom 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

Layout-only fields

Tab, horizontal group, and accordion

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.