News Feed
Jobs Feed
Sections




News Archive
SitePoint PHP Blog:
How to Tidy Your WordPress Menu HTML
January 26, 2011 @ 09:37:59

On the SitePoint PHP blog today there's a new post from Craig Buckler for the WordPress users out there. The HTML that this popular blog/CMS tools spits out can sometimes be not-so-semantic. Craig shares a tip on cleaning up one aspect of it - the methods returning lists for menus or sitemaps.

love WordPress. I also love clean semantic HTML. Unfortunately, several of the standard WordPress theme functions return code that is a little untidy. For me, the primary culprits are wp_list_pages() and the newer wp_nav_menu(); both return an unordered list of page links.

He gives an example of a sample list generated by wp_nav_menu() that's full of badly formatted and unnecessary elements. To help fix the issue, he shares his regular expression-based call to strip out things like extra tabs, empty classes and all title attributes. Obviously you can customize this as you need, but it's a good start towards something that's a bit cleaner and up to code.

0 comments voice your opinion now!
wordpress tidy html output pregreplace regularexpression menu


blog comments powered by Disqus

Similar Posts

Amazium Blog: PHP in the Dark: Input/Output

AnyExample.com: Bar chart HTML generator

Smashing Magazine: Create A Christmas Wish List With PHP (For Beginners)

Gareth Heyes' Blog: Regular expression challenge

Danne Lundqvist's Blog: Getting to grips with an existing XML structure


Community Events











Don't see your event here?
Let us know!


introduction code language framework functional unittest phpunit release development zendframework2 tool interview series podcast example conference testing application community opinion

All content copyright, 2013 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework