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

WP SITES

2662

Original Genesis Tutorials & 5000+ Guaranteed Code

Snippets

  • Support
  • Newsletter
  • Videos
  • Log in

Premium Member? - Request custom code

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

PHP Code

template_include

get_body_class

if else

array

class_exists

foreach

sprintf

add_action

printf

variable

Advertise · WPEngine · Genesis · Log in

  • How Premium Membership Works
  • Sign Up
  • Support
  • Subscription Details/Invoice
  • Tagged Tutorials
  • Access-Download Problems