Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When I read the nav items per wp get nav menu items the get_page_link( $id ) or $item->url does not give me the external URL I entered: http://www.mydomain.com.

Instead I seem to get http://www.mydoamin.com/wordpress/NameOfMenuItem

Any ideas?

I'm using permalinks and thought this might be the problem?

This is the menu code:

<?php

function bfShowHideMenu($menu_name, $args=array()) {

// Klassen von außen bestückbar
$bfListClass = "no-bullet bfZ1000";
$bfItemClassLevel1 = "";
$bfItemClassLevel2 = "";
$bfLinkClass = "navitem";
$bfContainerClass = "subScrollNavi";

$locations = get_nav_menu_locations();
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menuitems = wp_get_nav_menu_items( $menu->term_id );

echo '<ul class="' . $bfListClass . '">';

$count = 0;
$submenu = false;

foreach( $menuitems as $item ):
    // get page id from using menu item object id
    $id = get_post_meta( $item->ID, '_menu_item_object_id', true );
    // set up a page object to retrieve page data
    $page = get_page( $id );
    //$link = get_page_link( $id );
    $link = $item->url;

    // item does not have a parent so menu_item_parent equals 0 (false)
    if ( !$item->menu_item_parent ):

        // save this id for later comparison with sub-menu items
        $parent_id = $item->ID;

        // Hat der Knoten Kinder?
        $hasChildren = false;
        foreach( $menuitems as $child ){
            if ($child->menu_item_parent == $parent_id) {
                $hasChildren = true;
                break;   
            }
        }
        echo '<li class="';
        if ($hasChildren) echo "bfSHTrigger";
        echo ' ' . $bfItemClassLevel1 . '">';

        echo '<a href="' . $link . '" class="' . $bfLinkClass . '">';
            echo mb_strtoupper($page->post_title);
        echo '</a>';

    endif;

    if ( $parent_id == $item->menu_item_parent ):

        if ( !$submenu ): 

            $submenu = true;

            echo '<div class="bfSHContainer bfSHSubScrollNavi ' . $bfContainerClass . '">';
            echo '<ul class="' . $bfListClass . '">';  
        endif;

        echo '<li class="' . $bfItemClassLevel2 . '">';
        echo '<a href="' . $link . '" class="' . $bfLinkClass . '">' . mb_strtoupper($page->post_title) . '</a>';
        echo '</li>';

        if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id && $submenu ):

            echo '</ul>';
            echo '</div>';

            $submenu = false; 
        endif;

    endif;

    if ( $menuitems[ $count + 1 ]->menu_item_parent != $parent_id ):
        echo '</li>';

        $submenu = false; 
    endif;

    $count++; 
endforeach;

echo '</ul>';     

}
?>

share|improve this question
    
please add the code you are using to the question. –  Milo Feb 17 at 2:41
    
Hi, should have done that from the beginning. Edited the post. –  Matthias Max Feb 17 at 8:38

1 Answer 1

For some reason when I use $link = $item->url now it works. Instead of $link = get_page_link( $id ).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.