Before today, I was using a plugin for add jQuery UI tabs in WordPress. but today I have tried one thing to use jQuery UI tabs in WordPress without a plugin and extra JS files.
Latest WordPress 3.5 includes its own version of jQuery and many of the most common plugins. So We can develop tabbing functionality without using any plugins or extra JavaScript files.
Read about: To get Last auto increment id in WordPress
You do not need to package your own (especially not an older version) and instead use wp_enqueue_script() to pull in WordPress’s version.
Let’s dive into the code.
First of all, enqueue jquery core ui and ui tabs by adding action which is explained below.you can include below code into themes functions.php
file
1 2 3 4 5 6 7 8 | wp_enqueue_script('jquery-ui-core');// enqueue jQuery UI Core wp_enqueue_script('jquery-ui-tabs');// enqueue jQuery UI Tabs } add_action( 'wp_enqueue_scripts', 'load_custom_scripts' ); |
Now, you can write the script to call your tabs see below for a code.
1 2 3 4 5 | jQuery(document).ready(function($){ $("#tabs").tabs(); }); |
Next and last is to place your HTML content for tabbing format and place your content and text you want to display.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <div id="tabs"> <ul> <li><a href="#tab-1"><span>First Tab</span></a></li> <li><a href="#tab-2"><span>Second Tab</span></a></li> <li><a href="#tab-3"><span>Third Tab</span></a></li> </ul> <div id="tab-1"> <p> your first tab content goes here </div> <div id="tab-2"> <p> your second tab content goes here </div> <div id="tab-3"> <p> your third tab content goes here </div> </div> |
Also Read: To get Last auto increment id in WordPress
That’s it.Now you can see your front with tabbing. you are done it without any plugin. 🙂
Thank you for reading.Feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.
Comments (3)