If you’re using Oxygen Builder, you’ve probably seen the PHP Function Return Value option under dynamic data.
A lot of people skip over it, assuming they need a Repeater or a Custom Code Block to display dynamic content. That’s not always the case.
This isn’t about adding a full PHP snippet inside a Custom Code Block. That approach works, but it mixes logic and layout in a way that’s harder to maintain.
Instead, this is about writing a simple function in your code snippets or custom functions plugin. Then, calling it inside Oxygen’s PHP Function Return Value option to fetch a single piece of dynamic data.
This keeps your code separate, makes pages load faster, and avoids unnecessary loops.
If you need to grab a custom field from a specific post, a featured testimonial, or a pricing value from an ACF field, this is the best way to do it.
Oxygen provides a few ways to insert dynamic data. But they each have limitations when working outside of a post’s template.
Oxygen has built-in support for Advanced Custom Fields.
If you're inside a post template, you can insert ACF fields dynamically without using PHP.
But Oxygen doesn’t provide a way to reference a specific post from anywhere else on the site.
If you want to display an ACF field from a post that’s not the one being viewed, PHP is required.
Oxygen’s dynamic data options allow you to insert content from the current post, like the title, date, and custom fields.
But there is no built-in way to manually select a different post unless you use a Repeater or a custom query.
If you need to reference a specific post’s field on another page, you need a better solution.
A Repeater in Oxygen is designed for looping through multiple posts.
If you’re displaying a list of testimonials, a grid of blog posts, or a directory of businesses, a Repeater makes sense.
But if you just need to pull one piece of data from a specific post, it’s unnecessary.
Here are a few cases where PHP Function Return Value makes more sense than a Repeater.
Repeaters add extra queries and unnecessary markup when all you need is one value.
PHP Function Return Value keeps things cleaner and more efficient.
To use this in Oxygen, you first need to write a simple function.
If you’re not comfortable with PHP, don’t worry. This is about as simple as it gets.
Let’s say you have a custom post type called Rate. Each rate has an APY field.
You want to display that APY dynamically without looping through multiple posts.
Here’s how you set up the function. Remember, Oxygen Builder doesn't run off of a theme so this function needs to go in your code snippets or custom functions plugin.
function get_rate($post_id) { if (!$post_id || !is_numeric($post_id)) { return 'Invalid Rate ID'; } $rate = get_field('apy', $post_id); if (!$rate) { return 'Rate not available'; } return esc_html($rate) . '%'; }
When you use this function inside Oxygen, you need to pass in a post ID so the function knows which post to get data from.
In Plain PHP it looks like this:
get_rate(22)
get_rate
is the name of the function. This tells Oxygen to run the function we created.22
is the post ID of the Rate post we want data from.apy
field for post ID 22 and returns the value.If you wanted to display a different rate, you would change the number inside the parentheses.
For example,
would pull the APY from the Rate post with ID 35.get_rate(35)
But Oxygen gives us a built in way to do this with the visual editor.
A Repeater is designed for looping through multiple posts or custom fields.
It’s great when you need to display a list of items, like a blog archive or a team member section.
But if you just need one field from one post, a Repeater is overkill.
A Custom Code Block in Oxygen lets you write raw PHP inside Oxygen itself.
That can be useful, but it also ties your PHP directly to your page layout, making it harder to manage and debug.
Using PHP Function Return instead of a Custom Code Block keeps your PHP separate from your page layout.
But for pulling simple data from a post, PHP Function Return is the cleaner and easier solution.
Shortcodes are a common way to insert dynamic content in WordPress. But in Oxygen Builder, they don’t work inside text elements. If you add a shortcode inside a text block, it will display as plain text instead of running.
To use a shortcode, you would need to structure the layout differently. The text and dynamic value would have to be inside a div. The static text would go in one element, while the shortcode would go in another.
Then, you’d have to use flexbox or CSS to align them properly. This adds extra steps and makes the layout more complex.
With PHP Function Return, you don’t need extra structure. You can insert dynamic data directly inside a text element. This keeps everything clean and easy to manage.
I first used this method on a pricing table for a financial services website.
They had a post type for different financial products, each with fields for APY, APR, and other rates.
The client wanted these rates to be editable in one place but displayed across multiple pages.
By using PHP Function Return, I could pull in the rates dynamically without a Repeater.
If the client updated a rate, it automatically changed everywhere.
Another great use case was for a featured testimonial on a homepage.
Instead of setting up a Repeater and filtering it down to one post, I created a field where the client could select the featured testimonial.
This function pulled in the testimonial dynamically.
function get_featured_testimonial($post_id) { if (!$post_id || !is_numeric($post_id)) { return 'Invalid Testimonial ID'; } $testimonial = get_field('testimonial_text', $post_id); if (!$testimonial) { return 'No testimonial found.'; } return esc_html($testimonial); }
This approach kept things simple and made updates instant.
Oxygen Builder has strong built-in dynamic data features.
But it lacks an easy way to pull a field from a specific post.
The ACF integration works, but only inside a post template.
Dynamic data binding lets you reference the current post, but not another post unless you use a Repeater.
If you’ve been using Repeaters for everything, take a second look at whether you really need them.
If you’re only pulling one piece of data from a known post, PHP Function Return is almost always the better choice.
Try it out in your next Oxygen project and see how much cleaner your workflow becomes.