1

A WordPress project consists of normal first-level pages and some pages that have children. Instead of having single child pages, there is a template for any page that has children that pulls the content from its children and puts each child page’s content into a corresponding div. How can I create a custom walker in order to have all child-page links (and only them) turn to hashed links (using the child page slug), so it opens up the parent page and jumps to the corresponding section? (I would rather not use Javascript to detect and alter the anchor reverences for SEO purposes.)

Example/In detail:

I have three first-level pages, no child pages, linked to in my navigation, e.g.

About | Topic 1 | Topic 2

and then a fourth (and possibly fifth, sixth…) page Topic 3 that has three child pages (Sub-topic 3.1, Sub-topic 3.2and Sub-topic 3.3), so the menu then should receive two levels, realised by a drop-down menu for Topic 3:

About | Topic 1 | Topic 2 | Topic 3
                          | Sub-topic 3.1
                          | Sub-topic 3.2
                          | Sub-topic 3.3

Normally, the links to children, when created through the WordPress menu backend option, would look like

domain.url/topic3/sub-topic-3.1

, but should be turned into

domain.url/topic3/#sub-topic-3.1, for child pages only.

Your Answer

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

Browse other questions tagged or ask your own question.