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.Subscribe for new Genesis Tutorials