<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Digging into WordPress &#187; XHTML</title>
	<atom:link href="http://digwp.com/category/xhtml/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Fri, 18 May 2012 18:21:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>HTML Formatting for Custom Menus</title>
		<link>http://digwp.com/2011/11/html-formatting-custom-menus/</link>
		<comments>http://digwp.com/2011/11/html-formatting-custom-menus/#comments</comments>
		<pubDate>Mon, 28 Nov 2011 18:09:42 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[menu]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=5440</guid>
		<description><![CDATA[For some projects, it&#8217;s nice to output clean, well-formatted markup. Using theme template files enables great control over most of your (X)HTML formatting, but not so much for automated functionality involving stuff like widgets and custom menus. One of my current projects requires clean, semantic HTML markup for all web pages, but also takes advantage [...]]]></description>
			<content:encoded><![CDATA[<p>For some projects, it&#8217;s nice to output clean, well-formatted markup. Using theme template files enables great control over most of your (X)HTML formatting, but not so much for automated functionality involving stuff like widgets and custom menus. One of my current projects requires clean, semantic HTML markup for all web pages, but also takes advantage of WordPress&#8217; custom-menu functionality to make things easy. In this <abbr title="Digging into WordPress">DiW</abbr> article, we&#8217;ll see how to enjoy both: WordPress custom menus <em>and</em> clean, well-formatted HTML markup.</p>
<p><span id="more-5440"></span></p>
<h3>Customizing HTML displayed with wp_nav_menu()</h3>
<p>By default, <a href="http://digwp.com/2010/08/using-menus-in-wordpress-3-0/" title="Using Menus in WordPress 3.0">WordPress custom menus</a> are displayed in your theme template using the <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu">wp_nav_menu</a> function, which by default outputs markup that looks like this:</p>
<pre><code>&lt;div class="menu-test-container"&gt;&lt;ul id="menu-test" class="menu"&gt;&lt;li id="menu-item-6" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-6"&gt;&lt;a href="http://example.com/"&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-7" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7"&gt;&lt;a href="http://example.com/demos/"&gt;Demos&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-8" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8"&gt;&lt;a href="http://example.com/downloads/"&gt;Downloads&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-9" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-9"&gt;&lt;a href="http://example.com/docs/"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</code></pre>
<p>That&#8217;s a <em>mess</em> of <code>class</code> and <code>id</code> attributes, plus an extra <code>&lt;div&gt;</code> container to boot. Fortunately, the <code>wp_nav_menu()</code> provides some useful parameters for customizing the display of your custom navigation menus. Here is a list of the <em>default parameters</em>:</p>
<pre><code>&lt;?php $defaults = array(
  'theme_location'  =&gt; ,
  'menu'            =&gt; , 
  'container'       =&gt; 'div', 
  'container_class' =&gt; 'menu-{menu slug}-container', 
  'container_id'    =&gt; ,
  'menu_class'      =&gt; 'menu', 
  'menu_id'         =&gt; ,
  'echo'            =&gt; true,
  'fallback_cb'     =&gt; 'wp_page_menu',
  'before'          =&gt; ,
  'after'           =&gt; ,
  'link_before'     =&gt; ,
  'link_after'      =&gt; ,
  'items_wrap'      =&gt; '&lt;ul id=\"%1$s\" class=\"%2$s\"&gt;%3$s&lt;/ul&gt;',
  'depth'           =&gt; 0,
  'walker'          =&gt; );
?&gt;</code></pre>
<p>Of these parameters, <code>$container</code> lets you specify how to wrap the <code>&lt;ul&gt;</code> element, using either <code>'div'</code>, <code>'nav'</code>, or <code>false</code>. So by specifying <code>false</code> for the <code>$container</code> parameter, we can simplify markup by removing the <code>&lt;div&gt;</code> container. The <code>wp_nav_menu</code> function also provides two more optional parameters for customizing menu markup:</p>
<ul>
<li><code>$items_wrap</code> &ndash; &#8220;Whatever to wrap the items with an ul, and how to wrap them with&#8221; (source: WP Codex)</li>
<li><code>$walker</code> &ndash; &#8220;Custom walker object to use (Note: You must pass an actual object to use, not a string)&#8221; (source: WP Codex)</li>
</ul>
<p>These <em>sound</em> useful, but I haven&#8217;t had much luck with either. The <code>$items_wrap</code> didn&#8217;t seem to do anything, but there are plenty of <a href="http://wordpress.stackexchange.com/questions/14037/menu-items-description/14039#14039">custom</a> <a href="http://erikshosting.com/wordpress-tips-code/building-a-wordpress-walker-creating-custom-dynamic-menu-outputs/">walker</a> <a href="http://benword.com/2011/how-to-hide-that-youre-using-wordpress/">scripts</a> available for further experimentation and customization. If you can get them to work properly, <strong>a custom walker provides complete control over custom-menu markup</strong> displayed with the <code>wp_nav_menu</code> tag. Unfortunately, I was unable to get very far with any of them, so I sought an alternate method..</p>
<h3>An alternative approach for custom markup</h3>
<p>After fiddling with a few of the various custom walkers, I decided to find an <em>easier way</em> to customize and format WordPress nav/menu markup. The walkers are fairly extensive and complex, and just seem like overkill for building a simple list of custom menu items. After some digging through the WordPress Codex, I found the <em>perfect</em> function for crafting squeaky-clean WordPress menus: <a href="http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items">wp_get_nav_menu_items</a>. As the name implies, <code>wp_get_nav_menu_items</code> returns the items from your custom navigation menus (as created in the WP Admin → Appearance → Menus panel). Thus, you can use this function to mark up your custom menus however you want. For my particular project, the desired format looks like this:</p>
<pre><code>&lt;nav&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href="http://example.com/"&gt;Home&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/demos/"&gt;Demos&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/downloads/"&gt;Downloads&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/docs/"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/nav&gt;</code></pre>
<p>Trying to do this with the commonly used <code>wp_nav_menu</code> function and a custom walker is possible, but it&#8217;s <em>much easier</em> building the menu structure from scratch, using only what&#8217;s required to make it happen. So alternately we use <code>wp_get_nav_menu_items</code> and begin with the <a href="http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items#Building_simple_menu_list">example function</a> provided at the Codex. After wrapping it in a <code>function</code> and customizing the output, we have the <code>clean_custom_menus()</code> function, ready for copy/paste into your theme&#8217;s <code>functions.php</code> file:</p>
<pre><code>// custom menu example @ http://digwp.com/2011/11/html-formatting-custom-menus/
function clean_custom_menus() {
	$menu_name = 'nav-primary'; // specify custom menu slug
	if (($locations = get_nav_menu_locations()) &amp;&amp; isset($locations[$menu_name])) {
		$menu = wp_get_nav_menu_object($locations[$menu_name]);
		$menu_items = wp_get_nav_menu_items($menu-&gt;term_id);

		$menu_list = '&lt;nav&gt;' ."\n";
		$menu_list .= "\t\t\t\t". '&lt;ul&gt;' ."\n";
		foreach ((array) $menu_items as $key =&gt; $menu_item) {
			$title = $menu_item-&gt;title;
			$url = $menu_item-&gt;url;
			$menu_list .= "\t\t\t\t\t". '&lt;li&gt;&lt;a href="'. $url .'"&gt;'. $title .'&lt;/a&gt;&lt;/li&gt;' ."\n";
		}
		$menu_list .= "\t\t\t\t". '&lt;/ul&gt;' ."\n";
		$menu_list .= "\t\t\t". '&lt;/nav&gt;' ."\n";
	} else {
		// $menu_list = '&lt;!-- no list defined --&gt;';
	}
	echo $menu_list;
}</code></pre>
<p>After placing in your <code>functions.php</code> file, you can call the function and display your custom menus anywhere in your theme by calling it directly:</p>
<p><code>&lt;?php if (function_exists(clean_custom_menus())) clean_custom_menus(); ?&gt;</code></p>
<p>Then, you can customize the <code>clean_custom_menus()</code> function as follows:</p>
<ol>
<li><strong>Line 3:</strong> specify your custom-menu slug</li>
<li><strong>Lines 8 thru 15:</strong> customize markup, tabs, and line breaks as needed</li>
<li><strong>Line 17:</strong> uncomment <code>else</code> condition and customize if needed</li>
</ol>
<p>For lines 8-15, anything is possible &ndash; you can include whatever list items, markup, and attributes required. Additionally, you can tab and indent markup to line up with page markup using <code>\n</code> for a new line and <code>\t</code> for a tab space. The fastest, easiest way to use this function is to copy/paste into your theme and then check out your list markup. For example, if the nav list is too far to the left, add some more tabs. You can also add <code>class</code> and <code>id</code> attributes, include custom items, and even manipulate which list items are displayed (<code>$url</code>, <code>$title</code>, etc.). After a little fine-tuning, <strong>the <code>wp_get_nav_menu_items()</code> function enables clean, well-formatted markup for your custom menus</strong>.</p>
<h3>Quick Summary</h3>
<p>In this article, we explain two ways to clean up and customize WordPress&#8217; custom-menu markup. Either of these methods will take your code from this:</p>
<pre><code>&lt;div class="menu-test-container"&gt;&lt;ul id="menu-test" class="menu"&gt;&lt;li id="menu-item-6" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-6"&gt;&lt;a href="http://example.com/"&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-7" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7"&gt;&lt;a href="http://example.com/demos/"&gt;Demos&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-8" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-8"&gt;&lt;a href="http://example.com/downloads/"&gt;Downloads&lt;/a&gt;&lt;/li&gt;
&lt;li id="menu-item-9" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-9"&gt;&lt;a href="http://example.com/docs/"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</code></pre>
<p>..to this:</p>
<pre><code>&lt;nav&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href="http://example.com/"&gt;Home&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/demos/"&gt;Demos&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/downloads/"&gt;Downloads&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://example.com/docs/"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/nav&gt;</code></pre>
<p>..or whatever HTML structure that&#8217;s required. You can achieve this with either of these methods:</p>
<ul>
<li>Combine <code>wp_nav_menu()</code> with a custom walker class</li>
<li>Combine <code>wp_get_nav_menu_items()</code> with the <code>clean_custom_menus()</code> function</li>
</ul>
<p>As usual, if you know of better ways of doing something, please share in the comments! Thanks for reading Digging into WordPress :)</p>
<hr />
<p><small>© 2011 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2011/11/html-formatting-custom-menus/">Permalink</a> | <a href="http://digwp.com/2011/11/html-formatting-custom-menus/#comments">43 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2011/11/html-formatting-custom-menus/&title=HTML Formatting for Custom Menus">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/html/" rel="tag">HTML</a>, <a href="http://digwp.com/tag/menu/" rel="tag">menu</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2011/11/html-formatting-custom-menus/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>Poll: HTML or XHTML for Markup?</title>
		<link>http://digwp.com/2010/04/poll-html-or-xhtml-for-markup/</link>
		<comments>http://digwp.com/2010/04/poll-html-or-xhtml-for-markup/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 16:38:31 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[polls]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1964</guid>
		<description><![CDATA[HTML5 is rapidly gaining popularity, but how many people are actually using it? If not HTML5, then what? When creating websites, designers have a variety of options for markup: HTML5 (Not quiite official yet) HTML 4.01 (Strict, Transitional, Frameset) XHTML 1.0 (Strict, Transitional, Frameset, &#38; Basic) XHTML 1.1 (+ Basic XHTML 1.1) You can build [...]]]></description>
			<content:encoded><![CDATA[<p>HTML5 is rapidly gaining popularity, but how many people are actually using it? If not HTML5, then what? When creating websites, designers have a variety of options for markup:</p>
<ul>
<li><strong>HTML5</strong> (Not <em>quiite</em> official yet)</li>
<li><strong>HTML 4.01</strong> (Strict, Transitional, Frameset)</li>
<li><strong>XHTML 1.0</strong> (Strict, Transitional, Frameset, &amp; Basic)</li>
<li><strong>XHTML 1.1</strong> (+ Basic XHTML 1.1)</li>
</ul>
<p>You can build beautiful websites using any of these languages, but each comes with its own pros and cons. For example, you get some <a href="http://www.w3.org/TR/html5-diff/" title="HTML5 differences from HTML4">great new features with HTML5</a>, but JavaScript is required to ensure cross-browser compatibility. XHTML 1.0 is cool, but Internet Explorer doesn&rsquo;t really get it. Likewise, XHTML 1.1 is clean and flexible, but a little more persnickety about the details. <a href="http://www.zeldman.com/2009/07/02/xhtml-wtf/" title="XHTML DOA WTF">And whatever happened to XHTML <strong>2</strong></a>?</p>
<p>In a cage match, which markup language would dominate? <strong>Cast your vote</strong>!</p>
Note: There is a poll embedded within this post, please visit the site to participate in this post's poll.
<p><span id="more-1964"></span></p>
<p>Bonus question: How many of us will be around for HTML6? ;)</p>
<p><small>Note: If you are reading via feed, visit the <a href="http://digwp.com/" title="Digging into WordPress">DiW site</a> to take the poll (located in the sidebar).</small></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/04/poll-html-or-xhtml-for-markup/">Permalink</a> | <a href="http://digwp.com/2010/04/poll-html-or-xhtml-for-markup/#comments">39 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/04/poll-html-or-xhtml-for-markup/&title=Poll: HTML or XHTML for Markup?">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/polls/" rel="tag">polls</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/04/poll-html-or-xhtml-for-markup/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Clean Up Empty Elements with CSS 3</title>
		<link>http://digwp.com/2009/10/clean-up-empty-elements-css3/</link>
		<comments>http://digwp.com/2009/10/clean-up-empty-elements-css3/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 13:07:38 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=767</guid>
		<description><![CDATA[By default, WordPress wraps HTML comments with paragraph tags: WordPress also employs various template tags that may, in certain situations, result in empty HTML elements such as paragraphs tags: &#60;p&#62;&#60;/p&#62; &#60;p&#62;&#60;!-- --&#62;&#60;/p&#62; Other cases where empty elements are generated by WordPress involve images, line breaks, nested lists and other complex markup scenarios. Besides invalid markup, [...]]]></description>
			<content:encoded><![CDATA[<p>By default, WordPress wraps <acronym title="Hypertext Markup Language">HTML</acronym> comments with paragraph tags:</p>
<p>WordPress also employs various template tags that may, in certain situations, result in empty <acronym title="Hypertext Markup Language">HTML</acronym> elements such as paragraphs tags:</p>
<pre><code>&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;!-- --&gt;&lt;/p&gt;</code></pre>
<p>Other cases where empty elements are generated by WordPress involve images, line breaks, nested lists and other complex markup scenarios.</p>
<p><span id="more-767"></span></p>
<p>Besides invalid markup, the problem with this is that your <acronym title="Cascading Style Sheets">CSS</acronym> may be applying styles to the empty elements, potentially breaking your layout or disrupting the presentational harmony of your design.</p>
<p>For specifically targeted elements, such as paragraph elements for navigational template tags, dealing with this issue is as simple as this:</p>
<pre><code>#nav {
	display: none;
	}</code></pre>
<p>Either that or you could get all &ldquo;Google-homepage&rdquo; and use nothing but style-neutral <code>span</code>s and <code>div</code>s to markup your content. Unfortunately neither of these solutions is effective at alleviating the occasional, unpredictable WordPress-generated empty paragraph elements.</p>
<p>Fortunately, the new <code>:empty</code> pseudo-selector of <acronym title="Cascading Style Sheets">CSS</acronym>&nbsp;3 is the perfect solution for neutralizing <em>all</em> empty <acronym title="Hypertext Markup Language">HTML</acronym> elements. Here are some examples..</p>
<p>To neutralize all empty paragraphs (and only empty paragraphs), throw down the following slice of <acronym title="Cascading Style Sheets">CSS</acronym> goodness:</p>
<pre><code>p:empty {
	display: none;
	}</code></pre>
<p>Or, to cover your bases and hide <em>all</em> empty elements, add this bad boy to your stylesheet and enjoy complete satisfaction:</p>
<pre><code>*:empty {
	display: none;
	}</code></pre>
<p>In my opinion, this declaration should be included in all <acronym title="Cascading Style Sheets">CSS</acronym> reset stylesheets, but I will leave that decision up to you.</p>
<h3>But..</h3>
<p>Note that, for now, this technique only works in supportive browsers, which seems to be anything based on Mozilla. Unfortunately, Safari applies the rule to all elements of the specified element type. Hopefully this will be addressed in an upcoming version. And of course, Internet Explorer has absolutely no idea what we&rsquo;re talking about here.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/10/clean-up-empty-elements-css3/">Permalink</a> | <a href="http://digwp.com/2009/10/clean-up-empty-elements-css3/#comments">13 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/10/clean-up-empty-elements-css3/&title=Clean Up Empty Elements with CSS 3">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/css/" rel="tag">CSS</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/10/clean-up-empty-elements-css3/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

