• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

Prepend Letter Before & Append Letter After Custom Field Value

This code shows you how to automatically add a letter or letters before the dynamic value from a custom field as well as add letter(s) after the value.

$time       = get_post_meta( get_the_ID(), 'totalTime', true );
$PTM        = 'PT' . $time . 'M';
$time_PTM   = $time  ? $PTM : 'PT5M';

In this example, the letters PT are prepended before the custom field value and the letter M is appended after.

This enables you to use a custom field to add the value as a number so the result would be something like PT8M which relates to 8 mins.

If no value is added, a default value of PT5M is output as seem in the 3rd line of code which uses a ternary operator.

Used for schema totalTime as seen in the 1st example of this JSON script.

Custom Fields

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags