Voxel Mods: Randomize Output

The Randomise Output Mod for the Voxel WordPress theme lets you take a comma-separated list of values (for example, gallery image IDs, multiple taxonomy values, or even dynamic text lists) and return a randomised subset of that list on each page load.

What This Mod Does

The modifier performs the following steps:

  1. Accepts a comma-separated input list (numbers, text, etc.)
  2. Trims and sanitises each value
  3. Removes duplicate values
  4. Randomises the order of the remaining items
  5. Outputs only the number of results you specify (leave blank to give all results)

Each page refresh shuffles the results, keeping your content feeling fresh and dynamic.

This makes it ideal for rotating gallery images, featured media, keywords, or other repeatable content while keeping full control over how many items are displayed.

Use Cases

Displaying Random Gallery Images

Different gallery images with each page refresh.

When applied to a Gallery widget, the modifier can accept:

  • A comma-separated list of gallery image IDs
  • Additional image or file IDs from the Media Library
  • Dynamic tags that resolve to attachment IDs

The modifier will then:

  • Remove any duplicate image IDs
  • Shuffle the available images
  • Output only the chosen number of images

This is perfect for:

  • Rotating featured images
  • Random hero or banner imagery
  • Highlighting different gallery items on each visit

Unleash Dynamic Data with Voxel!

With Voxel’s design flexibility, the possibilities are endless. Get Voxel here!

Randomising Text or Keyword Output

A list of keywords, with the random output set to only show 1 result on each page refresh

When applied to a Text widget, the Randomise Mod can be used to randomly output:

  • A random subset of values from the comma-separated list including dynamic tag values

This becomes far more powerful when paired with:

  • Repeaters
  • Keyword lists

In these cases, you can rely entirely on the input list and let the modifier output a random selection without adding any additional options.

Combining multiple data sources

Two or more galleries joined using the append mod. Add more items to the single append input, separated by a comma.

It is possible to combine multiple galleries or other data types together using Voxels Append Mod – just add a comma to separate the data sources.

Conclusion

In conclusion, the Randomize Output Modifier for Voxel offers a simple yet powerful solution for introducing dynamic, randomized content into your WordPress site.

By accepting comma-separated lists and additional input options, this modifier provides flexibility and ease of use, allowing you to add engaging features like rotating gallery images, random taxonomies, or diverse content displays with minimal effort.

Coupled with robust security measures such as input sanitization and output escaping, this tool ensures a safe and smooth user experience.

Whether you’re looking to spice up your site’s content or provide a more interactive experience for your visitors, the Randomize Output Modifier is an invaluable addition to your Voxel toolkit.

The Code: Randomize Output Mod

v3 – The code was updated to choose the number of output results.

*** Disclaimer – Use at your own risk. Always make a backup. ***

Add to your child theme’s functions.php file.

add_filter( 'voxel/dynamic-data/modifiers', function( $modifiers ) {

    class Randomize_Output_Modifier extends \Voxel\Dynamic_Data\Modifiers\Base_Modifier {

        public function get_label(): string {
            return 'Randomize Output';
        }

        public function get_key(): string {
            return 'randomize_output';
        }

        protected function define_args(): void {

            $this->define_arg( [
                'type'    => 'number',
                'label'   => _x( 'Max items to return (0 = all)', 'modifiers', 'voxel-backend' ),
                'default' => 0,
            ] );
        }

        public function apply( string $value ) {

            if ( empty( $value ) ) {
                return esc_html( $value );
            }

            // Split comma-separated list
            $items = explode( ',', $value );

            // Trim + sanitize
            $items = array_map( function( $item ) {
                return sanitize_text_field( trim( $item ) );
            }, $items );

            // Remove empty + duplicates
            $items = array_values( array_unique( array_filter( $items ) ) );

            if ( empty( $items ) ) {
                return '';
            }

            // Randomize order
            shuffle( $items );

            // Apply limit
            $limit = absint( $this->get_arg(0) );
            if ( $limit > 0 ) {
                $items = array_slice( $items, 0, $limit );
            }

            return esc_html( implode( ', ', $items ) );
        }
    }

    $modifiers['randomize_output'] = \Randomize_Output_Modifier::class;
    return $modifiers;

} );

To implement this mod, you’ll need to add the code to your WordPress site. You have two options for where to place this code:

  • Child Theme’s functions.php File:

    If you’re already using a child theme (recommended for customization), simply add the PHP code to your functions.php file. This will ensure your changes are preserved even if the main Voxel theme is updated.

  • Code Snippets Plugin:

    If you prefer not to edit theme files directly, or if you want to manage your custom code more easily, you can use the Fluent Snippets plugin. This plugin allows you to add custom PHP code without touching your theme files. Just create a new function.php snippet, paste the code, and activate it.

Then apply this Voxel Mod from the Elementor builder interface.

More Articles

Displaying parent categories with their child categories grouped underneath in Voxel is difficult and not directly supported by default term feed options. To achieve this, you need to use a term loop workaround that allows child terms to be looped inside a parent term preview. The steps below show how to do this using native […]
Voxel Framework is a new WordPress plugin in development that brings Voxel’s features to Bricks Builder and Gutenberg. While Voxel can create custom post types, taxonomies, and custom fields — and supports powerful dynamic data, conditional logic, and visibility rules — its real value goes far beyond content structure. Details below are speculative based on […]