Hi Guys,
Today i will explain how to use short code for custom menu item in navigation.
I have tried and got the result for it. Here i explained how i did it.
First you have to install the this plugin for url short-code -> http://wordpress.org/extend/plugins/peters-blog-url-shortcodes/
Add this code to your functions.php file with your theme.
class description_walker extends Walker_Nav_Menu{
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
//echo $item->url;
$string = explode('::', $item->url, 3);
if($string[1]){
$string[1] = str_replace('-',' ', $string[1] );
$item->url = do_shortcode("[$string[1]]");
}
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$prepend = '';
$append = '';
$description = ! empty( $item->description ) ? ''.esc_attr( $item->description ).'' : '';
if($depth != 0)
{
$description = $append = $prepend = "";
}
$item_output = $args->before;
$item_output .= '';
$item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
$item_output .= $description.$args->link_after;
$item_output .= '';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
Then you have to call this function from wp_nav_menu from the templates files.
$arg = array( 'menu' => "main-menu", 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'depth' => 0, 'walker' => new description_walker() );
wp_nav_menu( $arg );
Thats it. Then go to the back-end with menu section.
For example i want to give the page URL to custom link.
I will add like this —–> http://::blogurl-id=’1302′::
That’s All.
Now you can go to the front-end and check the shortcode will work.
Thanks.