1

If the menu is with Pages then how can I display the menu item links like this:

http://example.com/#/page/id

I want to use the menu with Angular routes.

I believe this can be done with a custom Walker.

3
  • What do u mean by If the menu is with Pages ? Also, instead of providing a link to a page with no menus, u'd better provide an image of desired output Commented Dec 21, 2015 at 16:29
  • The menu is with Pages, meaning that it has only Pages in it (no custom links, no categories etc). I just want the link as a desired output, no styling. Commented Dec 21, 2015 at 16:31
  • I would suggest e.g. the nav_menu_link_attributes filter.
    – birgire
    Commented Dec 21, 2015 at 16:34

1 Answer 1

3

You can try the following to modify the links of the menu items that are pages:

add_filter( 'nav_menu_link_attributes', function( $atts, $item, $args, $depth )
{
    if( 
          isset( $item->object ) 
       && 'page' === $item->object 
       && isset( $args->theme_location ) 
       && 'primary' === $args->theme_location 
    )
        $atts['href'] = home_url( 
            sprintf( '/#/page/%d',  $item->object_id ) 
        );

    return $atts;
}, 10, 4 );

where we target the primary theme location.

This should give this kind of links:

http://example.tld/#/page/12345
1
  • you're welcome, glad it worked for you @KlevisMiho
    – birgire
    Commented Dec 23, 2015 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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