I am trying to use wordpress to make a website replicate... So, when the viewer comes to http://www.wpsite.com/1005, I do a check (through an API) to see if the id is a valid/active rep, then set a cookie for the usual stuff (name, email, repid) and redirect to the main page:
http://www.wpsite.com/wp/?page_id=34&id=1005
I have all of this functioning currently.
so at this point, I want to pass the "id=1005" to ALL of the menu links at the top of the page. My site is using the Appearance -> Menus functionality in wordpress to build the menu...
So when the viewer hovers over/clicks any link on the site, I want the "&id=1005" to be added to it. Is that possible? What if the user isn't valid and there is no "&id=1005"? Thanks.
Adam
Update: Ok, I create a walker class, but I am still confused where to put the querystring "id" value so it displays in each one:
// Walker Nav Menu
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 . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
$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 ) .'"' : '';
$prepend = '<b>';
$append = '</b>';
$description = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';
if($depth != 0)
{
$description = $append = $prepend = "";
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
$item_output .= $description.$args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
I have a feeling it's in the "attributes" section... something with those tertiary expressions... Like "if id not ''" add THIS... but I'm missing it...
Any help is appreciated.
Adam
There are no filters available to modify the
href
atteribute. To do this you need to create a custom walker. And build your own menu. It's not that hard to do.More information: