Modify button URL based on query string paramters
-
I’m wondering if this plugin would allow me to modify the URL a button opens based on the query string parameters passed to the page?
-
Yes, it is possible. It depends on some factors, such as which page builder you are using and how the button is set up (feasibility comes down to whether the button’s link field accepts shortcodes or not).
If it doesn’t work out of the box, it shouldn’t be complicated to create the button in a way that does—using HTML, for example.
As for pulling the query string into the link, you have two options:
- Query String DKI shortcode – You pick a parameter, and the value of that parameter is generated automatically.
https://www.if-so.com/query-string-dki-shortcode/ - Trigger with a Page URL condition – For example, if the page URL contains
?your_parameter=value, you can set up the link manually according to your needs when the condition is met.
https://www.if-so.com/help/documentation/page_url/
Came here to respond to a reply I received via email, but I don’t see that reply here. Anyway, let me describe the scenerios I’m after.
I’d like to be able to receive to the same page different parameters like so:
https://mydomain.com/mywebpage
https://mydomain.com/mywebpage/123
https://mydomain.com/mywebpage/234
https://mydomain.com/mywebpage/345Based on these I’d like to do two things. One is aim a text link to different urls based on the received parameter. The second is to set the URL a button clicks through to also to different urls.
So for the first scenario it might be like this:
https://mydomain.com/apage
123 = https://somedomain.com/somepage
234 = https://someotherdomain/anotherpage
345 = https://yetanotherdomain/yetanotherpage
Will want to be able to do that same for a button, either a Gutenburg button or HTML based if I must.Is there a link that would show me how to do these. Or could someone provide me with a response that shows how?
It’s important to distinguish between a permalink and a parameter.
In your example (https://mydomain.com/mywebpage/123), the number is a permalink.
A parameter, on the other hand, is an addition to the URL that doesn’t change the base address. A parameter consists of a key and a value, and looks like this:example.com?parameter=valueOr, when chaining multiple parameters:
example.com?parameter=value¶meter2=value2There are several possible solutions, and all of them may be relevant in your case. To guide you toward the best option, it’s important to:
- Understand how many different parameters or permalinks you will need.
- Determine whether you can use parameters instead of permalinks.
Yes parameters will work fine. Just one for a give page.
Given that can you share with me how I would implement a solution based on the examples I gave, replacing the permalink approach with a parameter for the ending different values?
If you only have a single parameter per page, the easiest solution is to duplicate the Gutenberg button and set an If-So condition for each one:
- First button: If → Page URL → does not contain → your parameter name and value
- Second button: If → Page URL → contains → your parameter name and value
For each button, you can then set the relevant link.
Yes initially I moved toward that. Ultimately I ended up coding a shortcode that sets the values of the button based on the query parameter.
- Query String DKI shortcode – You pick a parameter, and the value of that parameter is generated automatically.
You must be logged in to reply to this topic.