php - Is it possible to create custom menus in WordPress with titles without links? -
we building theme on wordpress 3.5.1 , created 2 custom menus - 1 header , 1 footer. in footer titles not linkable, therefore created custom links href "#" , changed href "". result empty links <a>
. know it's possible change cursor of these empty links css:
.footer-content #sitemap ul.menu > li.menu-item > { cursor: text; }
and found out way remove these empty links javascript , jquery:
$('.footer-content #sitemap ul.menu > li.menu-item > a').each(function() { // if href empty, remove <a> element. var href = $(this).attr('href'); var href_length = 0; if (!(typeof href === 'undefined')) { var href_length = href.length; } if (href_length === 0) { var contents = $(this).contents(); $(this).replacewith(contents); } });
(the footer menu inside .footer-content #sitemap
elements:
<div class="footer-content"> <div id="sitemap" class="not_mobile">
)
but possible remove empty <a>
elements html without using javascript? function creates footer menu is:
<?php wp_nav_menu( array( 'theme_location' => 'footer_menu' ) ); ?>
thanks, uri @ initech.
yes, possible. can use walker
. put following class in functions.php
file
class themeslug_walker_nav_menu extends walker_nav_menu { // add main/sub classes li's , links function start_el( &$output, $item, $depth, $args ) { global $wp_query; $indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent // depth dependent classes $depth_classes = array( ( $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ), ( $depth >=2 ? 'sub-sub-menu-item' : '' ), ( $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ), 'menu-item-depth-' . $depth ); $depth_class_names = esc_attr( implode( ' ', $depth_classes ) ); // passed classes $classes = empty( $item->classes ) ? array() : (array) $item->classes; $class_names = esc_attr( implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ) ); // build html $output .= $indent . '<li id="nav-menu-item-'. $item->id . '" class="' . $depth_class_names . ' ' . $class_names . '">'; // link attributes $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 ) .'"' : ''; $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : ''; $attributes .= ' class="menu-link ' . ( $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ) . '"'; if($depth == 0) { $item_output = sprintf( '%1$s%2$s%3$s%4$s%5$s', $args->before, $args->link_before, apply_filters( 'the_title', $item->title, $item->id ), $args->link_after, $args->after ); } else { $item_output = sprintf( '%1$s<a%2$s>%3$s%4$s%5$s</a>%6$s', $args->before, $attributes, $args->link_before, apply_filters( 'the_title', $item->title, $item->id ), $args->link_after, $args->after ); } // build html $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } }
and add walker in wp_nav_menu
function <?php wp_nav_menu( array( 'theme_location' => 'footer_menu', 'walker' => new themeslug_walker_nav_menu ) ); ?>
this remove anchor tag <a>
each menu item.
Comments
Post a Comment