Solution 1 :

There’s an easier way to do this, and it requires no JavaScript. Use the :target CSS selector.

<div class="tab" id="tab1">
  <h1>This is Tab #1</h1>

<div class="tab" id="tab2">
  <h1>This is Tab #2</h1>

In your CSS, start with something like this:

.tab {
  display: none;
.tab:target {
  display: block;

Then, when you go to page.html#tab1, you’ll see the first tab. Or, page.html#tab2, you’ll see the second.

This should you get you started. You’ll obviously want to set your CSS rules such that one of the tabs is showing by default, for when the page is shown without an anchor fragment. And, you’ll want to link to these anchor fragments from somewhere.

Solution 2 :

In your case to load a link with specific tab as active you utilize your URL Hash more:

If you have this link:


<script language="javascript" type="text/javascript">
  if(window.location.hash) { // Check if url hash is not empty
      var hash = window.location.hash; // nav-y1

Solution 3 :

I have found the solution to my own question:

In functions.php I added the code:

function wwp_custom_query_vars_filter($vars) {
    $vars[] = 'tab';
    return $vars;
add_filter( 'query_vars', 'wwp_custom_query_vars_filter' );

And in the topics.php I added:


To the url

and in content.php I added the conditions check by calling:


Problem :

I have 3 php files content.php, functions.php and topics.php
I want that when a user clicks on an link in topics.php that they get redirected to a page with tab1 open and that on the same link but at different button that tab2 is open when they click on the link.

I have tried code with onClick=”” and with jquery but none of that has worked.

The active tab must reflect where on the site the user has clicked (i.e. whether the user clicked the first ‘Algebra’ link or the second one).

The links are defined and created in topics.php


Comment posted by Quang Thái

maybe in this function: onClick=”selectTab(“nav-y1″)”. Have you tried the id “navtab-y1” ( onClick=”selectTab(“navtab-y1”))

Comment posted by Brad

@LiamBartsch Just use

Comment posted by Brad

@LiamBartsch Yeah, that’s not at all what your question says. You said, “How to open link with specific tab active”. If what you actually want to ask is something completely different, you should just make a new question at this point.

Comment posted by Jovylle

here i have checked your link

Comment posted by Jovylle

i also tested it and it worked out, it automatically clicked the button it needed to click

Comment posted by

Thanks Jovylle but how do I call that script from the code: dont update the tag, i am currently using this “Past Papers With Solutions