News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

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

ProDevTips.com: WP Hashcash

Nick Halstead's Blog: Programming Tips #9 "debug_backtrace"

Christian Stocker\'s Blog: \"Wordpress hat den Blog-Hosting Markt versaut\"

DevShed: An Object-based Approach to HTTP Compression in PHP

Community News: WordPress Security Update Released


Community Events











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


symfony2 composer application hhvm series component podcast unittest introduction hack release database opinion language security performance facebook framework package install

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