In the WPDevDesign facebook group, a member asked about having a section that uses a random image from a pool of images as a background. In this premium tutorial we'll walkthrough how to do it in Oxygen

We'll go through the following steps;

  • Create a gallery field with ACF Pro, applied to pages.
  • Create a custom function to return the URL of one random image from that gallery field.
  • Use Oxygen's dynamic data options to apply that URL as our section background image.

Create a gallery field with ACF Pro

The gallery field works well for this as it's an intuitive way the client can add a number of images to be randomly selected from.

We'll name our gallery field 'hero-background', apply it to pages, and be sure the 'return format' setting is set to 'image array'.

Create our function

We'll need to create a custom function that takes the array of images from the gallery and returns the URL of one of those images, chosen randomly.

In our code snippets, we can create a function with this code;

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($37/month or $399 one-time).

Already a member? Log in below or here.

Need help implementing a tutorial in your site or want to hire me for custom work?

HIRE ME

Find the article helpful and wish to donate?

DONATE

Comments

For adding code blocks wrap the code in three backticks. Markdown should work.
Provide a URL of your site/webpage if something is not working.
magnifiercross
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: