How to Show Elements Based on URL parameters

Last update:

Recently I had a project where I was to show a button based on an URL parameter. Oxygen Builder is my go-to tool for page building, and it has the native and outstanding Conditions function to show elements, from sections to spans, however there is no preset for URL parameters. So I was making a little digging, tried a few things, then I ended up using this solution on Stackoverflow (SO). For reference, I am attaching the relevant answer here, but you can find the whole dicussion on SO.

This post is about how to implement the solution above in Oxygen Builder.

Implementation

So I took the code and made a custom PHP function in Advanced Scripts:

function currenturl_callback() {
    global $wp;
    $current_url = home_url(add_query_arg($_GET,$wp->request));
    return $current_url;
}

Some explanation:

  • currenturl_callback is the name of the function chosen by me. You can write here any other unique name,
  • current_url is the name of a variable I used here, as you can find also in the solution on SO. Feel free to modify it.

As a result we now have function to use in Oxygen’s Conditions, namely here:

Choose "Dynamic Data" on on the dropdown.
Choose “Dynamic Data” on on the dropdown

Oxygen Conditions

The following images help you to find what to select and where you write to:

Select Advanced > PHP Function Value
Select Advanced > PHP Function Value
Type in the name of the function you just created.
Type in the name of the function you just created

After this step you end up to see the final part of making the condition. You will see the following window.

And here it is all up to you. I used the contains condition, and then wrote the specific part of the URL I wanted to base my condition on.

Conclusion

This solution is working for me, and I hope you can use it too. Feel free to share your solution, or raise any questions about this method in the comments section. I try to answer them all. Cheers!