A Cozmoslabs Product
Documentation / Custom Fields Creator / HTML Custom Field

HTML Custom Field

Overview

This Default Field Type is available in WordPress Creation Kit free version. The HTML Field is used to add HTML content.

Creating a HTML Field

To add a HTML Field to a previously created Custom Meta Box, under the Meta Box Fields tab simply insert a Field Title and under Field Type make sure you select HTML.

WordPress Creation Kit - Custom Fields Creator - Meta Box Fields - HTML Field

The HTML Field contains options to customize it:

  1. Description – Allows you to specify a description for the HTML Field
  2. HTML Content – Allows you to add your HTML content

Page, Post or Custom Post Type Edit Screen

This is how the HTML Field we created above looks like in the Edit Screen:

WordPress Creation Kit - Custom Fields Creator - Meta Box Fields - HTML Field (Editor)

Template usage

The following examples are for a Custom Meta Box with the “Group Name” argument “my_meta_name“. Make sure to replace this with the “Group Name” you have set up. The Custom Meta Box below is setup to be attached to a post.

WordPress Creation Kit - Custom Fields Creator - Meta Box Arguments - Template

Using the WCK Custom Fields API

The HTML Field returns a string containing html code.

For a Single Meta Box

To output a value inside The Loop we use the function the_cfc_field():

1
Value: <!--?php the_cfc_field('my_meta_name', 'my-html'); ?-->

To assign the value to a variable we use the function get_cfc_field():

1
<!--?php $first_html = get_cfc_field('my_meta_name', 'my-html'); ?-->

For a Repeater Meta Box

To output all the “My Html” entries from the repeater field we use the functions get_cfc_meta() and the_cfc_field():

1
<!--?php foreach( get_cfc_meta( 'my_meta_name' ) as $key =&gt; $value ){ the_cfc_field( 'my_meta_name','my-html', false, $key ); } ?-->

To output a specific “My Html” entry from the repeater field (e.g. the second entry), we use the function the_cfc_field():

1
<!--?php the_cfc_field( 'my_meta_name','my-html', false, 1 ); ?-->

The index starts at 0 so that’s why we pass “1” to the function. For the first entry it would be “0”, the second is “1”, the third is “2” and so on…

Using the default WordPress functions

For a Single Meta Box

1
<!--?php $my_meta = get_post_meta( $post-&gt;ID, 'my_meta_name', true ); if( !empty( $my_meta[0]['my-html'] ) ) echo 'Value:'.$my_meta[0]['my-html']; ?-->

For a Repeater Meta Box

To output all the “My Html” entries in the repeater field:

1
<!--?php $my_meta = get_post_meta( $post-&gt;ID, 'my_meta_name', true ); if( !empty( $my_meta ) ){ foreach( $my_meta as $entry ){ echo $entry['my-html']; } } ?-->

To output a specific “My Html” entry from the repeater field (e.g. the second entry):

1
<!--?php $my_meta = get_post_meta( $post-&gt;ID, 'my_meta_name', true ); if( !empty( $my_meta[1]['my-html'] ) ) echo $my_meta[1]['my-html']; ?-->

The index starts at 0 so that’s why we pass “1” to the function. For the first entry it would be “0”, the second is “1”, the third is “2” and so on…

After version 2.0 we can also get fields directly

1
<!--?php /* get the first entry */ $first_value = get_post_meta( $post-&gt;ID, 'my-html', true ); /* get the third entry */ $third_value = get_post_meta( $post-&gt;ID, 'my-html_2', true ); ?-->

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket