I'm not really sure how to phrase the questions, but hope it's not too confusing.

Basically I've create a plugin which inject custom tabs into the posts content when displaying. For now, just assume I'm using DomTab, and I have permalink configured as /%category%/%postname%/. Now I would like achieve 2 things with the tabs.

  1. Beautify the url by appending the tab name to the url according to the tab highlighted. e.g. If tab "Detail" is clicked/highlighted, the url should change from http://myhost/catgegory/post1/ to http://myhost/catgegory/post1/detail/ without requiring to refreshing the page, much like how google did it. The content of all the tabs are preloaded and hidden.
  2. When url with the tab name are access directly, say from a bookmark, the tab should be highlighted automatically. e.g. If user access http://myhost/catgegory/post1/comment/ then the "Comment" tab should highlighted instead of the default tab when displayed.

I don't really need a full solution to this, but hints of where to start. As I understand query, but not sure how to access it with permalink enable.


EDIT: Currently accessing http://myhost/catgegory/post1/comment/ ends up in 404

1 Answer 1


I've found out the solutions, though not perfect, but it gets the job done. Following is the code

add_action('init', 'my_init');

function project_ace2_init()
    global $wp;
    $wp->add_query_var('tab'); // Needed so get_query_var('tab') will work
        //'(.+?)/([^/]+)(/([^/]+))?/?$', //Original : '(.+?)/([^/]+)(/[0-9]+)?/?$'

The rule is taken from the default Wordpress rules for permalink as /%category%/%postname%/, I just modified the last numeric portion into alphabetical. This method will require refreshing of page when changing tab, but it's good enough for now.

Next is getting the tab name so I can be highlight, which is simpler with just this $selected_tab = get_query_var('tab');

EDIT: Updated rewrite rules to fix bug where page/2/ is captured

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.