Yesterday got an IM from my buddy Atom Groom about an issue he was having with a WordPress project he was working on. I’d personally never run into the issue before and it didn’t really make sense when he was first explaining it. I setup a test instance and finally realized what was going on.
When using the wp_list_pages() function to generate your navigation it will add a class of “current_page_item” to the current page in that list. As well when you are on a child of another page the parent page will get a class of “current_page_parent”. Now this is great overall because with little work you can easily setup a nice navigation system.
So what’s the problem? By default the search and 404 pages have the main posts page set as their parent. So now when you’re on one of those pages your navigation show that as the parent page of this one. There is no easy way in the admin side to stop this or to set what the parent would be for those cases (if anyone knows of a way please let me know as I obviously missed it.) So went ahead did the normal thing you have to do when you want to remove those strange default things WordPress does automatically, used a filter on the wp_list_pages() function. Code is below (Link to Gist if not showing up) –
What’s strange is I couldn’t easily find any information on this issue. I couldn’t believe that more people hadn’t run into this issue before and that it would be talked about. Then it hit me why this probably isn’t an issue, people more often then not probably don’t use the static page and posts page. As well, when doing a standard blog, most handle the “home” in their navigation separate from the rest so it wasn’t being auto generated (or don’t even have a home link in the nav because they expect you to click the header.)
With WordPress becoming more of a CMS I think people will run into this more and more. So I figured why not write a post and hope that this can help someone out there with the same info who might not be finding anything.
So enjoy, if you have any questions please ask.Comments: 10 Tags: