1

I'm creating a website in WordPress that has child pages for multiple locations.

For example, the main page has a Home, About, and Contact pages + 15 service pages. And the location pages have the About, Contact, and the 15 service pages duplicated. I have links in the about page linking to the 15 services. Now If I could have a relative link it would be as easy as duplicating this section. What I want the link to do is that if you are on
https://example.com/about/ and you click a service
it takes you to https://example.com/service1/
but if you are on https://example.com/location/
the same link structure takes you to https://example.com/location/service1

I don't want to have to create 15 different links + different menu links for every single location when all you need to do is add service1/ to the end of the slug you are on.

1 Answer 1

0

In Wordpress you should always use the built-in "menu" functionality: You create a menu once (in the WP backend, on the "Design > Menues" page), give it a name, define a position in your PHP template (for example the header.php file) and assign that position to that menu (in the WP backend again). WP will take care of the correct filepaths, regardless on which page you are, by dynamically creating absolute links when parsing the pages. And you can create as many menues as you want, for example the main navigation, footer nav, sidebar menu or whatever.

Here's a simple example for the code in a php template:

<nav id="main_nav">
    <?php
        $arguments = array(
          'theme-location' => 'main_menu_1',
          'container' => 'ul'
        );
        wp_nav_menu($arguments);
    ?>
</nav>
1
  • What About a page section that links to different services and that is located under every location? Commented Mar 3, 2022 at 1:18

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.