Contents
Overview
Sometimes you need to change the output of the field value depending on where you’re displaying it in your theme. Maybe you need a different date format in different locations, or you want to apply some very specific conditional formatting that is beyond the capabilities of the limited Magic Tags and Template Tags available to the Pods Templating engine. That’s when you can use WordPress functions or your own PHP functions against the contents of the field output.
Quick Start
- Create a function stored in your functions.php or an external plugin file. The function should take one parameter and return one value or string.
- Inside your Pods Templates, call that function against one of your fields with the syntax
{@custom_field,my_function}
Using Functions On Field Output
You can pass the output of any field through any available function with the form {@field_name,any_function}
. For example, to sanitize the output from a field for href
links or the attributes within them, you may do {@field_name,esc_attr}
or {@field_name,esc_html}
or {@field_name,esc_url}
.
Special Functions for Audio & Video and white-listed oEmbed Providers
Audio & Video
For situations where you’d use the or
shortcode in WordPress, we’ve created two special functions
pods_audio
for Audio and pods_video
for video.
ie, {@audio_field_url,pods_audio}
or {@video_field_url,pods_video}
oEmbed Providers
For external media files via white-listed oEmbed providers, ie YouTube, Vimeo, etc, it’s better to do:
{@audio_field,wp_oembed_get}
and {@video_field,wp_oembed_get}
in templates or use wp_oembed_get() directly in PHP. Good reference on that here:
http://webdesignforidiots.net/2014/01/pulling-a-video-from-a-posts-content-and-displaying-it/
You can also directly use an oEmbed Field.