0

I have a landing page with 3 buttons that have respective functions with them to hide/unhide content based on user selection of those three buttons.

Is there a way I can have the user land directly on a particular function?

so the base URL is domain.com/page

domain.com/page/function1 would land on the page with function1 enabled.

2
  • What type of function? JavaScript/jQuery? PHP? Commented Oct 18, 2018 at 10:41
  • Oh sorry about the delay. I didn't see the notification. It's javascript native Commented Oct 28, 2018 at 9:20

1 Answer 1

0

You have a few options.


GET Parameter
The easiest one is to add a GET parameter to the url of the links, so you call it like this: domain.com/page?function=1

Then, on your page page, you can access this parameter using global array $_GET['function'] and do your logic as you wish.


POST Parameter - wrap into forms
If you don't want it to be seen, you can wrap your links in separate form elements, with action set to domain.com/page, the link would be an input type='submit', and also add an input field type='hidden' with name='function' value='1'. Then you can access this value on your page page with global $_POST['function'] array. More about forms here.


Register custom routes
You can do exactly like you wanted, accessing domain.com/page/1 can make the get_query_var('function') set to 1 on page page, but you need to register a custom url route in WordPress.

This has been answered already, so I'll just point you to it here.


Warning
Whatever option you choose, please don't forget to wrap the value of your parameter inside htmlspecialchars() function. More about that here.

1
  • Sorry for delayed response. Thanks, dboris. Pardon me for being a little new to this. I'll explore these a little bit more and find what works. Commented Oct 28, 2018 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.