0

I want to use tabs plugin and load tab contents using ajax. The problem is: the plugin requires a solid .php file to be specified in href e.g.

<li><a href="ajax/content3-slow.php">Tab 3 (slow)</a></li>

You know this does not work well with WordPress. A callback here would have worked. Is there such fork available Or any other plugin?

2

You can always use the proper WordPress Ajax API (well not really an api) for example:

<li><a href="url to wp-admin/admin-ajax.php?action=my_ajax_tabs&tab=tab1">Tab 1</a></li>
<li><a href="url to wp-admin/admin-ajax.php?action=my_ajax_tabs&tab=tab2">Tab 2</a></li>

then you create a function that will respond to the ajax calls:

function do_my_tabs(){
    $tab = $_GET['tab'];
    switch ($tab){
    case "tab1":
        echo 'tab1 content';
        break;
    case "tab2":
        echo 'tab2 content';
        break;
    }
    die();
}

and last just hook this function :

//if you want only logged in users to access this function use this hook
add_action('wp_ajax_my_ajax_tabs', 'do_my_tabs');

//if you want none logged in users to access this function use this hook
add_action('wp_ajax_nopriv_my_ajax_tabs', 'do_my_tabs');

//if you want both logged in users and guests to access this function then add both
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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