I'm building a fullpage Wordpress site. Meaning the pages are not separate URLs, they are accessed through the same URL. Something like deuxhuithuit.com.

So I have a menu that the admin creates by selecting different pages. Wordpress generates the unordered list of links with URLs like http://mysite.com/page-slug. I want my theme to change those links into hashes to the same URL `http://mysite.com#page-slug.

Any ideas?

  • how are you generating the list of links, a nav menu? – Milo Sep 16 '14 at 17:54
  • I think you should add custom links in your menu. Each section must have post-id so you can add like http://mysite.com#post-id – Robert hue Sep 16 '14 at 18:09
  • @Milo, right, a nav menu – Mauro Sep 16 '14 at 18:21
  • @Roberthue, yeah I know that. But I want the admin to easily edit the menu without the need of typing the slug. He's not very techie and he'll be editing the menu quite frequently. – Mauro Sep 16 '14 at 18:23
  • you could use a custom walker function to update the output of the urls – karpstrucking Sep 16 '14 at 20:54

Here's how I solved it so far.

class themename_walker_nav_menu extends Walker_Nav_Menu {
     function start_el( &$output, $item, $depth, $args ) {
        $slug = get_post( $item->object_id )->post_name;
        $item->url = "#{$slug}";
        return parent::start_el( $output, $item, $depth, $args  );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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