594

How to Control Content Visibility with URL Parameters in Oxygen Builder

Control content visibility in Oxygen Builder using URL parameters. This Oxygen condition checks the ‘access’ URL parameter against a defined value, allowing you to hide specific content unless the parameter matches. Ideal for previewing unreleased content on the front-end while logged out.


<?php

add_action('plugins_loaded', function () {

    if (function_exists('oxygen_vsb_register_condition')) {

        global $oxy_condition_operators;

        // Condition to check if a URL parameter is present.
        oxygen_vsb_register_condition('Access Code', array('options' => array(), 'custom' => true), $oxy_condition_operators['string'], 'oxy_access_code_callback', 'Other');

        function oxy_access_code_callback($value, $operator)
        {

            if ($operator == '==') {

                if (!empty($_GET['access']) && $_GET['access'] == $value) {
                    return true;
                } else {
                    return false;
                }

            } else if ($operator == '!=') {

                if (empty($_GET['access']) || $_GET['access'] != $value) {
                    return true;
                } else {
                    return false;
                }

            }

        }

    }
});

Other Snippets

WPCodeBox is a WordPress Code Snippets Manager that allows you to share your WordPress Code Snippets across your sites.