How to add php in WordPress Menu -


i'd add php code links of wordpress menu. use

dashboard > appearance > menus 

to make menu. if add php code there, doesn't work.

i need menu links like:

<a href="http://mcadrives.com/?ref=<?php code goes here?>"> 

if want querystring present on every menu item have based through custom walker, should add code?

the php coding have been using on every hyperlink , image this:

<a href="http://mcadrives.com/?ref=     <?php        if (!empty ( $_server['query_string'])){          echo substr($_server['query_string'],4); }        else{           echo 'mhammonds'; }     ?>> 

i know add functions.php file , call walker in wp_nav_menu, , how add coding?

    class query_nav extends walker_nav_menu {     function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {         global $wp_query;         $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';          $class_names = $value = '';          $classes = empty( $item->classes ) ? array() : (array) $item->classes;         $classes[] = 'menu-item-' . $item->id;          $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );         $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';          $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->id, $item, $args );         $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';          $output .= $indent . '<li' . $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        ) .'"' : '';          //add php here determine whatever need link         $addedstuff = 'some added stuff append url';         $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url.$addedstuff) .'"' : '';         ////////////////////          $item_output = $args->before;         $item_output .= '<a'. $attributes .'>';         $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->id ) . $args->link_after;         $item_output .= '</a>';         $item_output .= $args->after;          $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );     } } 

in query_nav walker class, change line:

$addedstuff = 'some added stuff append url'; 

to these lines:

if ( ! empty ( $_server['query_string'] ) ) {      $addedstuff = '?ref=' . substr( $_server['query_string'], 4 ); }else {       $addedstuff = '?ref=mhammonds'; } 

and you're done... make sure call wp_nav_menu using walker.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -