WordPress plugin for a mobile friendly sticky navigation menu

Hello!

Creating a unique, original and flexible navigation menu in WordPress can be challenging. There are many commercial and free plugins out there to establish navigation systems, however many of the commercial options seem to be “overkill” providing many bloated options with embedded CSS that can be difficult to adjust by a novice user.

What we wanted to do is put together a very simple and clean navigation menu that sticks to the top of the screen and is mobile friendly in a simple yet flexible way.

We created a plugin, which you can view by clicking here, to do just that!

The plugin utilizes FontAwesome, Modernizr, Google Fonts and CSS from Codyhouse to put together a simple and clean navigation menu solution. Below I’ll walk through the different components that went into this plugin in order to tie everything together in an easy to use solution.

Register settings to customize the menu

We wanted to give enough flexibility to customize the look and feel of the navigation menu so that novice users could style the menu elements themselves. More advanced users can easily overwrite the classes in their stylesheet to customize further if they wish. Future versions of the plugin may include even more styling options and behavior.

We have a total of 15 menu options in the back-end administration area. The options include choosing your Google font as well as overlay and menu bar color as well as opacity.

Some of the options above, when defined, perpetuate inline styling via the plugin in order to dynamically apply the CSS to the menu :

The last line in the above snippet wp_add_inline_style is what injects the CSS.

Use Google Fonts for your Menu

For an advanced user, you should be able to overwrite the fonts used for this navigation menu with whatever you want. Alternatively we have provided the ability to select any Google font from a list. Future versions will include weight and size selections. What we want is to build a list of Google fonts, return it as an array and then use that array as a select list for the user to choose in the administration settings for the plugin.

What was implemented was a function that gets the list of fonts straight from google, but saves the results in a cached file so that we dont have to query google every time the page is refreshed :

You can see above that we are making a simply query via curl to get the data, but before that we are checking to see if the cache file is out of date otherwise we will use the local file (which is much quicker anyways).

Once we store the returned array into a variable, we can simply loop through the array and build a simple select dropdown :

Color selector

The other interesting thing we did was implement a simple html color selector to easily choose your overlay, font and menu bar colors. In the plugin code when defining the options for the administration settings of the plugin, we implemented color options :

 

What you need to do is to load the wp-color-picker style and scripts so that you can utilize it.

Then you need to load your own jquery to implement the trigger for the color selection popup :

Inside the script you will see the jQuery trigger :

color-picker
There are a few other components but this should give a good overview of how we put everything together! Clean and modern sticky navigation menus are pretty straightforward to implement with pure HTML & CSS. In WordPress there are many bloated navigation menu plugins and systems integrated within themes. A clean, small and versatile menu system is always nice to have and hopefully will be useful 🙂