News 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

Community News: Canvas for WordPress (Drag and Drop Template Management)

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

Mindloop Blog: Htmlpurifier and the CodeIgniter framework

JSLabs Blog: How to write an image gallery script in PHP

Fabien Potencier's Blog: Getting information from SVN with PHP


Community Events





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


framework interview library laravel conference language composer artisanfiles symfony security podcast community version introduction voicesoftheelephpant tool list opinion release series

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