Site icon WP Smith

WordPress Facebook Navigation Shortcode: Insert the Nav or Menu Bar into Facebook Tabs Post

Now, creating Facebook tabs using Facebook Tab Manager (see previous post), only allowed me to create "pages." However, I wanted a menu system for my Facebook tabs to be controlled within my WordPress site, so instead of creating a template for Facebook Tab Manager that included a navigation system that connected all my Facebook Tabs, I created a navigation shortcode for users to insert their desired navigation menu, created in WordPress's custom menus and have further control. Since Facebook Tabs Posts are their own custom post type, creating a menu system for them is quite easy.

How the Facebook Nav Shortcode Works

To use the code, insert [fb_nav] into your post. It takes a few different arguments:

The default output code is:
[php]
<div id="nav"><div class="wrap">WP_NAV_MENU</div></div>
[/php]

Sample:
[fb_nav menu=39 custom_class='fun']

Code

You can download the code [download id="8"], insert into your child theme folder, and include the following in your functions.php file.
[php]require_once(TEMPLATEPATH.'/fb_nav_shortcode.php');[/php]

Or, here's the entire code that can be added to functions.php.
[php]
<?php
//nav shortcode
add_shortcode('fb_nav', 'fb_nav_shortcode');
function fb_nav_shortcode( $atts ) {
$defaults = array(
'container' => '',
'container_class' => '',
'menu' => '',
'menu_class'=> 'nav',
'custom_class'=>'',
'echo'=>0
);

$atts = shortcode_atts( $defaults, $atts );
$classes = $menu_setting;
$classes .= ' '. $atts['custom_class'];
$nav = wp_nav_menu(array(
'container' => $atts['container'],
'menu' => $atts['menu'],
'menu_class' => $classes,
'echo' => $atts['echo']
));

echo '<div id="nav"><div class="wrap'.$atts['container_class'].'">' . $nav . '</div></div>';
}
?>
[/php]