Aweber - Email Marketing Made Easy
Add a Fancy jQuery Drop Down Menu in Thesis using Superfish

Add a Fancy jQuery Drop Down Menu in Thesis using Superfish

January 9, 2011 · 26 comments

in Thesis

Thesis 1.x Notice: Thanks for reading this post! So, here's the deal. I wanted you to be aware that this post was written prior to the release of Thesis 2. So that means the instructions or other information provided applies specifically to Thesis 1.x and not the latest 2.x version. Thanks!

To create drop down menus in Thesis, you just add pages and assign a parent page to them. Then enable them in the Thesis options and voilà, you have a drop down menu. But what if you want to integrate some sort of fancy jQuery to the drop down menu so when you hover over the parent page, the list of child pages, or the sub menu, fades in elegantly. Well, here’s one solution.

For this tutorial, I’m using the Superfish menu jQuery plugin as I’ve used this before and is really easy to get working. Note that this tutorial is based off of version 1.4.8. Superfish is an enhanced Suckerfish-style menu jQuery plugin.

Step 1: Download the plugin

Visit this Superfish download page and download the zip file that contains all the files. I’m going to go through a basic installation, but you’re welcome of course to read more about the features on the Superfish website. The way I’m setting it up is based off the sample setup.

Step 2: Copy the files

For the basic installation which will result in a really nice, smooth jQuery drop down menu, copy these files into a folder called “js” in your custom folder inside the main Thesis folder:

  • hoverIntent.js
  • superfish.js

Now place this file in a folder called “css”, also inside the custom folder in your main Thesis theme folder:

  • superfish.css
The main css menu selector in the demo css file here uses a class called “.sf-menu”. You will need to do a search and replace on this file, replacing every instance of “.sf-menu” to “.menu“. There are some essential styles in this file that must be applied to the jQuery menu, so you’ll need to update the css class to match your Thesis menu class. Also, once you’re done, you will most likely want to change the value on line #32. Read the comment on that line for this to make sense.

Finally, copy all the images that appear in the “images” folder into your images folder inside your Thesis custom folder.

Step 3: Add the code

Now that you’ve copied over the necessary files, you need to reference them. Paste this code into your custom-functions.php file:

function superfish() {
?>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>

<!-- superfish jquery menu -->
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/custom/js/hoverIntent.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/custom/js/superfish.js"></script>

<script type="text/javascript">

	// initialise plugins
	jQuery(function(){
		jQuery('ul.menu').superfish();
	});

</script>

<?php
}

add_action('thesis_hook_after_html','superfish');
Important: Don’t load jQuery again if it’s already being loaded. You can view the source of your home page and search fro jquery. If it’s already there, don’t load it again as shown in line #4 above.

And you’ll need to add this code to load the custom Superfish stylesheet. Add the following to the custom-functions.php file:

/* superfish stylesheet */
function superfish_stylesheet() {
?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/custom/css/superfish.css" media="screen">
<?php
}

add_action('wp_head','superfish_stylesheet');

You’re Done!

Believe it or not, that’s it. The plugin takes care of the rest. I’d recommend that you look at some of the settings available to you that reside inside the superfish.js file around line #85. You can enable or disable certain features like shadows and arrows and also set the delay of the sub menu.

Let us know how it worked out for you in the comments!

Was this post helpful? Consider subscribing to my blog via RSS or

This Site Runs on the Thesis WordPress Theme

Thesis Theme thumbnail

If you're someone who doesn't understand a lot of PHP, HTML, or CSS, Thesis will give you a ton of functionality without having to alter any code. For the advanced user, Thesis has incredible customization possibilities via extensive hooks and filters. And with so many design options, you can use the template over and over and never have it look like the same site.

If you're more familiar with how websites work, you can use the fantastic Thesis User's Guide and world-class support forums to make more professional customizations than you ever thought possible. The theme is not only highly customizable, but it allows me to build sites with a much more targeted focus on monetization than ever before. You can find out more about Thesis below:

{ 26 comments… read them below or add one }

Mitch February 2, 2011 at 11:46 am

Awesome tutorial, thank you. I am getting a “jQuery(“ul.menu”).superfish is not a function error message. I tried the fix from here: http://terriswallow.com/weblog/2009/fix-jqueryul-sf-menu-superfish-is-not-a-function/

And I still get the error message, any thoughts or insights?

Thanks,

Mitch

Reply

Thesis-Blogs.com February 2, 2011 at 11:57 pm

Hi Mitch, I can’t really take a look to see if I can troubleshoot it for you because you hadn’t provided a link to the site in question. Maybe check to see that you aren’t loading jQuery twice.

Reply

Mitch February 3, 2011 at 8:53 am

Hey there,

My playbox is listed above.

Cheers,

M

Reply

Thesis-Blogs.com February 3, 2011 at 11:03 am

Mitch, I had a look at your site and the problem is that the two .js files referenced in the tutorial cannot be found. They need to be included in that “js” folder. If you look at the code by viewing the source of the page, then scroll to the bottom, you’ll see the code you added which references these files. Well, when you visit that URL, the file is not there.

Reply

Mitch February 3, 2011 at 1:46 pm

Duh, stupid me. I had the js folder in the incorrect location. Cheers!
Mitch recently posted..Lap Dances- Fundraisers- Sex Bloggers and Reid Gyrating for Speak Up! Feb 4th- NYC

Reply

David February 16, 2011 at 8:08 pm

Thanks for this. so easy!

Reply

Paul March 22, 2011 at 5:15 am

Hi,
Superfish has nice nav-bar style that makes a nice two-tiered nav menu. Could you tell me how to integrate it into Thesis. I’ve added the superfish-navbar.css file after the main superfish.css file, as it says on their site,into the function superfish_stylesheet, but have problem adding the class sf-navbar to the parent ul along with the usual sf-menu class. Can you explain me how to make it work?

Reply

Thesis-Blogs.com March 22, 2011 at 8:34 am

Hi Paul. Have you already followed the tutorial on this page? You’re asking how to integrate Superfish into Thesis, but that’s what this post is all about, so not totally following you here. Thanks for commenting.

Reply

Paul March 22, 2011 at 12:53 pm

Yes, your step-by-step tutorial is perfect and works very. But, it is for Superfish basic-style drop down menu. What I wanted to do was Superfish nav-bar-style menu. Here at the examples tab you can see the difference between those styles http://users.tpg.com.au/j_birch/plugins/superfish/#sample1
Superfish gives instructions on how to do it:
“To create a horizontal nav-bar with a horizontal second tier and optional vertical third tier, simply include the superfish-navbar.css file after the main superfish.css file and add the class sf-navbar to the parent ul along with the usual sf-menu class (space-separated, eg. class=”sf-menu sf-navbar”), and initialise as normal”
I think i’ve figured out the css part, but have problems with “add the class sf-navbar to the parent ul” part.

Reply

Thesis-Blogs.com March 23, 2011 at 5:29 pm

Hi Paul. I’d need to take a look at the site in question, but here are two short, quick, down and dirty answers for this:

1. I’d have to see the way you have the code structured but you might want to add a WordPress Menu for this because you have the ability to add a custom class to the wrapping div. But I don’t know offhand if the way you’re implementing this will work with the class on the wrapping div, or the parent UL as you indicated.

2. This might be the better solution for you. Add the class you need to the parent UL by using jQuery. I’ve explained a similar concept in this post on what to do if there’s no Thesis hook for that. But you’d need to use the .addClass() jQuery method explained here.

Hope that helps.

Reply

Paul March 24, 2011 at 2:13 am

My playground is still local, so i’ll post here the code from custom_functions.php
This is what i’ve got:

function addClass_sfnavbar() {
?>
<script>
$(document).ready(function() {
$("ul")
.addClass(‘menu sf-navbar’);
});
</script>
<?php
}
add_action('wp_head','addClass_sfnavbar');

function superfish() {
?>
<!– superfish jquery menu –>
<script type="text/javascript" src="<?php bloginfo(‘template_directory’); ?>/custom/js/hoverIntent.js"></script>
<script type="text/javascript" src="<?php bloginfo(‘template_directory’); ?>/custom/js/superfish.js"></script>

<script type="text/javascript">

// initialise plugins
jQuery(function(){
jQuery('ul.menu').superfish();
});

</script>

<?php
}

add_action('thesis_hook_after_html','superfish');

/* superfish stylesheet */
function superfish_stylesheet() {
?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo(‘template_directory’); ?>/custom/css/superfish.css" media="screen">
<link rel="stylesheet" type="text/css" href="<?php bloginfo(‘template_directory’); ?>/custom/css/superfish-navbar.css" media="screen">
<?php
}
add_action('wp_head','superfish_stylesheet');

what am i doing wrong?

Reply

Thesis-Blogs.com March 25, 2011 at 10:56 pm

I’d have to spend some time looking over all this code on your live site, but here’s what I usually do to troubleshoot something like this. If you can download a demo from the source that works, look at the HTML code behind the page that is working, and make sure that you replicate everything on that page in your Thesis theme using the appropriate hooks. Here are some things you can check:

  1. Is jQuery being loaded before the custom menu script?
  2. Is jQuery being loaded only once?
  3. When you view the source of the page, click the links that reference a jQuery plugin and make sure the links are good.
  4. Is there a conflict with another framework, if so use jQuery .noConflict.
  5. Check to make sure the class you’re adding with jQuery is actually being added.

Bottom line is that if you replicate the working demo completely, it should work.

Reply

Paul March 26, 2011 at 8:23 am

Checked all 5. It seems that class sf-navbar is not being added. Here is the function from custom-function.php file that i’m using to add the sf-navbar class:

function add_sfnavbar() {
?>
<script>
 $(document).ready(function() {
   $('ul.menu').addClass('sf-navbar');
 });
</script>
<?php
}

add_action('wp_head','add_sfnavbar');

i checked it couple of times, but couldn’t find a mistake. Any help?

Reply

Thesis-Blogs.com March 26, 2011 at 8:13 pm

I tried this code myself and it works just fine. It’s adding the script to the head section. Here’s what could be the problem for you though. When I used your original code it had a coupel of invalid quote character characters. Check to make sure that you’re using a single quote wherever it is being used in the code. I’d paste this code in a text editor and the type over the single quotes to make sure. I used this exact code and it did work.

Reply

Dave August 9, 2011 at 9:34 pm

This is a great tutorial. I’m having the same issue as Paul, however, at http://yupana.ca. At present I’ve got very nice pulldown menus thanks to this tutorial, but can’t get the horizontal ones working. I’m aiming for the kind of functionality you see in the “nav-bar style”:

http://users.tpg.com.au/j_birch/plugins/superfish/#examples

I’m no coder – I’m an accountant. I generally scour for some good copy & paste options and then feel out the glitches.

My first issue is that I don’t understand the language of “simply include the superfish-navbar.css file after the main superfish.css file and add the class sf-navbar to the parent ul along with the usual sf-menu class (space-separated, eg. class=”sf-menu sf-navbar”), and initialise as normal.” on http://users.tpg.com.au

Second, here’s what I’ve got for code that’s gotten me to where I’m at now:

custom_functions.php:

function add_sfnavbar() {
?>

 $(document).ready(function() {
   $('ul.menu').addClass('sf-navbar');
 });


<script type="text/javascript" src="/custom/js/hoverIntent.js">
<script type="text/javascript" src="/custom/js/superfish.js">

	// initialise plugins
	jQuery(function(){
		jQuery('ul.menu').superfish();
	});

<link rel="stylesheet" type="text/css" href="/custom/css/superfish.css" media="screen">
<link rel="stylesheet" type="text/css" href="/custom/css/superfish-navbar.css" media="screen">
<?php
}
add_action('wp_head','superfish_stylesheet');

The only changes I've made to any files that come with Superfish are the ones outlined in this tutorial. If you've got a minute, I'd love some feedback on where I might be going awry.

Reply

Thesis-Blogs.com August 9, 2011 at 9:51 pm

Hi Dave… I looked at what I believe is your site, but the code doesn’t seem to match up with what you pasted here. If you’d like just email me your WordPress site URL using the ‘Hire Me’ link in the menu and I’ll take a look. Please make sure you have at least one sub-sub menu, which is what I believe you’re trying to achieve here. Basically a three-tiered menu. I’ll see if I can take a look in the morning.

Reply

Dave August 9, 2011 at 9:53 pm

Will do, thanks.

The code didn’t paste properly at all, so I’ll do that.

Cheers!

Reply

Ken Jones April 27, 2011 at 4:41 am

Great tutorial. I don’t normally delve this deeply into JS and the like but I’ve been able to get this up and running on my testing site with minimal fuss in about an hour or so.
Had a few CSS tweaks to make but that was simple enough. The only problem I’m having now is with the positioning of the dropdown when it appears. Hovering over the top-level menu item causes the sub-menu overlay the top item. I need it to appear below the main nav bar. Can you point me in the right direction for changing the dropdown’s start point to make it appear below the main nav item please?
(PS My test site’s not publicly accessible but if you need to take a look at it to see what I mean feel free to email me at the address I’ve used to leave this comment and I’ll send you the link and a guest login. Thanks.)

Reply

Thesis-Blogs.com April 27, 2011 at 8:40 am

Feel free to email me this information. You can use the contact link in the footer.

Reply

bakescake September 27, 2011 at 11:18 am

Hi – trying to work on this locally. I have all files, etc. on my desktop. I’ve copied the code as you wrote above. How do I actually activate the menus? If I already have something in place, how does it get changed to the superfish menus? I’m looking to also use the nav-bar menu.
Any direction is much appreciated.
Thanks and I hope you still see these comments! :)

Reply

Thesis-Blogs.com September 27, 2011 at 11:32 am

There isn’t anything to “activate.” Just follow the directions above and it should just work. Thanks.

Reply

Techpur December 31, 2011 at 6:46 am

Can you suggest us a Good thesis skins , we are confused how we can design menu and all ..i like your blogs and turials , and also your blog looks and i think you can suggest us a good thesis skin
Techpur recently posted..How to Download all Facebook Albums Photos in Zip File

Reply

Thesis-Blogs.com December 31, 2011 at 9:10 am

Just search on Google for Thesis Skins, and you should find a couple of the top skin sites out there. You could also have one custom designed for you so it looks exactly how you want with the functionality you want. If that’s of interest, click the “Hire Me” link at the top and submit the form. Thanks.

Reply

Rachel January 24, 2012 at 11:26 pm

Thank you.

I followed your instructions exactly, but with that last bit of code to add this code to load the custom Superfish stylesheet my menu looked all funky. So i deleted that code and mine looks like: http://www.driostudio.com/services/marketing/
my question now is how do I edit those arrows and how do i fix it from shifting right after it drops down?
Rachel recently posted..Why website design?

Reply

Gabriel Bowen January 28, 2012 at 10:33 pm

So after a long time trying to get the nav-bar style to work, I’ve finally figured it out. And since this post helped me so much, I thought I might as well share the wealth.
(Please correct me if I’m wrong Thesis.blogs.com because I’m no coding expert).

Paul (above) was right with the coding part in custom_functions part. Here’s what I got:

function superfish() {
?>

<script type="text/javascript" src="/custom/js/hoverIntent.js">
<script type="text/javascript" src="/custom/js/superfish.js">

// initialise plugins
	$(document).ready(function() {
   $('ul.menu').addClass('sf-navbar');
 });


<link rel="stylesheet" type="text/css" href="/custom/css/superfish.css" media="screen">
<link rel="stylesheet" type="text/css" href="/custom/css/superfish-navbar.css" media="screen"> 
<?php
}

add_action('wp_head','superfish_stylesheet');

The most important part though is the custom.css:

.custom .menu li {
	display:inline-block;
	float:none;
}

You'll have to play around with ".custom .menu" and ".custom .menu a" to customize it even more.
I hope others find this useful. Thanks Thesis.blogs.com

Reply

Amandeep Singh August 1, 2012 at 2:18 am

I tried superfish on one of my blogs (oyeludhiana.com) and it looks great…. still need to improve it a bit to give it “The” look but looks better than the default nav which thesis comes with :)
Amandeep Singh recently posted..Pinboard – Pinterest Like Responsive WordPress Theme [30% Off]

Reply

Leave a Comment

When commenting, you can use basic HTML tags. If you are pasting in any code, please escape it here and then include that code within <pre></pre> tags. Thanks!

CommentLuv badge

Previous post:

Next post: