Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I now switched to permalinks and defined my own structure /%postname%. If I click on a menu item it takes the path from the parent page (hierarchy defined directly when editing a page). I want that the permalink uses the structure of the menu. How can this be done?

share|improve this question
What do you mean by 'takes the path from the parent page' - do you mean that the permalink of pages reflects its hierarchy: e.g. if page2A was a child of page1, it has permalink www.example.com/page1/page2a? – Stephen Harris May 1 '12 at 11:38
@StephenHarris: Yes, I mean that! This is the current situation and I want to change this behavior. The hierarchy of the menu should be chosen not the one of your example. – testing May 1 '12 at 12:14
1  
Why can't you set the parents according to the menu structure? (Or more usually, have the menu reflect the parent-child relationship). Why is there a difference between the page and menu relationships? – Stephen Harris May 1 '12 at 13:38
Yes, I could set the menu structure, but I don't know if the user would make this, when he creates a new page. The difference is here because I needed the hierarchy for some special adaptions I made (read the content from certain sub pages and so on ...). Normally, the menu should define the structure of the permalink. Thats the reason why I asked for it. And the menu hierarchy is already available. So one would have to define the hierarchy two times. Perhaps I don't understand a certain concept ... – testing May 1 '12 at 14:09
WP has a lot of complexities to account for in its URLs. I've been thinking about this exact same thing but there are many edge cases like feeds, single posts, comment pages, custom rewrite endpoints etc... Total nightmare – sanchothefat Jun 13 '12 at 16:46
show 1 more comment

1 Answer

THE PERMALINKS

The permalink on WordPress is generated by WP_Rewrite class on wp-includes/rewrite.php. It translate the URL being entered on browser into query variables which then being used by WP_Query to determine which content will be loaded.

There are rewrite rules which define the structure of permalink.

Categories are structured by default as website/category/category_name Pages are structured as website/pagename

and for posts: it is website/custom_structure, where custom_structure is what you define on the Setting > Permalink on admin page.

Pages, is by default reflecting it parents so third level page will have website/Level1/Level2/Level3

THE NAVIGATION MENU

The navigation menu doesn't reflect the permalink, it depends on how user will build the structure of the menu.

So, if you need the menu to follow the page structures, create a manu based on them. Having the permalink structure followed your menu takes more effort than you could imagine.

Having custom permalink is dealing with some actions. 1. You have to create custom structure for each part of your page which are categories, tags, port_formarts, taxonomies, posts etc. 2. You have create rewrite rule for them as well. 3. You have to make sure that they don't conflict each other.

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.