WordPress Theme Development Training Wheels: Day Three

WordPress Theme Development Training Wheels: Day Three

Tutorial Details
  • Program: WordPress
  • Version: 3.3.1
  • Difficulty: Beginner
  • Estimated Completion Time: 30mins
  • Prerequisites: Lesson 1 & 2 of this Series, Starting Files,Completed Files, Code Used
This entry is part 3 of 4 in the series WordPress Theme Development Training Wheels

After having dealt with manually coding various types of menus, we’ll wrap up menus in this lesson covering the Custom Menus functionality introduced in Version 3.0. Custom menus allow us to freely build menus from within the WordPress admin dashboard, by adding any combination of pages, category links and other custom links, whether they be internal site links or links to any other location on the web.


Step 1: Create a Functions File

In order to make use of the custom menu feature, we need to register a special PHP function, which enables the menus feature on the theme via the register_nav_menu function. The capability to insert custom menus does not exist as a default within the theme. We need to enable this functionality specifically, and create certain menu areas or "locations" via code where our custom menus will appear.

As we’ll see later, registering special functions will become quite important during more advanced theme development. In order to register functions in WordPress, we need to add a functions.php file to our theme’s files.

Create a Functions File

Create a blank file named functions.php in your theme’s root folder

Before we actually do anything to the functions file we can see that the Appearance > Menus in the Dashboard is pretty standard. No Menu Link to be seen.


Step 2: Register the Menu Function

Now we’ll register a custom menu using the following basic form of the register_nav_menu function.

  <?php register_nav_menu( $location, $description ); ?>

The location will be the menu’s identification name for use within the code, and the description will be a nice name used to display the menu’s description in the Dashboard. This would look something like the following.

  <?php register_nav_menu( 'primary', 'Primary Menu' ); ?>

“primary” would be used within the code which places the menu in the specific area of the template (location), and "Primary Menu" will be used to choose the menu location within the Appearance > Menus editing UI.

Once we’ve registered our menu, we can proceed to the Dashboard to create the menu via the menu editor.

The register_nav_menu function is placed within the functions.php file.

Take special care not to leave unnecessary whitespace after the functions code, as this can cause theme breakages.

Once this code is placed into your functions.php file, visit your dashboard again and refresh to see the new menu item under Appearance.

We can neaten up the registration code as we did with wp_list_pages and put the parameters into an array

<?php register_nav_menu(
  array(
	'theme_location' => 'bottom_header'
  ));
?>

Using arrays will be helpful when deciding to register more than one Custom Menu with additional parameters (coming up in a bit).


Step 3: Create a Menu via Dashboard

Now that we’ve registered a custom menu, we can go to Appearance > Menus to create our first Menu.

For a detailed guide on creating menus using the Menu Interface watching the following Video – WP 101 Video Training – Custom Menus

The Menu Creator interface has the following components:

  • Create new menus panel top right, which allows for creation of many different named menus
  • Custom links creator panel to add links to any URL into the menu
  • Pages panel to select existing pages from your site to the menu
  • Categories panel to add links to existing post categories to the menu

Should your site have any additional content types, for example custom post types, these will also have a panel to add to the menu.


Step 4: Placing the menu into the Theme

Placing custom menus into your theme templates requires using the wp_nav_menu() function. This function provides a location where menus built inside the dashboard can then be placed by default.

Below is the most basic form of the code needed for inserting a single menu from the menus which have been created.

<?php wp_nav_menu(); ?>

Default usage:

Which results in the following HTML

What’s the Result?

Firstly we notice that our original div & ul which wrapped the wp_nav_menu function are not entirely necessary as the function generates its own div and ul wrappers. What we do need to do is to specify the class and / or IDs which these will have. We will do this in a bit with some additional parameters.

The wp_nav_menu function we used does the following:

  • fetches the first menu created in the menu editor
  • adds a wrapper div, with custom class name based on the menu’s name we created, with -container appended
  • adds a ul container inside of the container which has a menu class by default and custom ID based on menu name
  • creates a list of menu items with custom menu-item classes instead of page-item class

The visual result below is due to the additional wrappers which conflict with some of the CSS we have in the theme, so we’ll need to edit the markup a bit and modify the placement function.

Broken CSS

Firstly we add a ‘container’ parameter to the placement code to tell it to generate an outer div container. The container can also be configured to generate an HTML5 ‘nav’ tag, or with the value ‘false’ can be told not to generate any containing element. These parameters effectively make the markup in our theme which currently wraps the menu placement code redundant, so we can now remove them. Here’s the code.

<?php wp_nav_menu(
	array(
		'container'       => 'div'
	)
); ?>

The next parameter (‘container_id’), is for specifying the ID attribute of the container div, so it conforms to our CSS we’ve already placed into the theme.

<?php wp_nav_menu(
	array(
		'container'       => 'div',
        'container_id'    => 'menu'
	)
); ?>

With the third parameter (‘menu_class’), we’ll change the default class on the ul wrapper from ‘menu’ to ‘bottom-menu-list’ as the .menu selector has already been used in our CSS for the fallback menu styles which we’ll discuss a bit later on in the lesson.

<?php wp_nav_menu(
	array(
		'container'       => 'div',
		'container_id'    => 'menu',
		'menu_class'      => 'bottom-menu-list'
	)
); ?>

We can now place this code into the theme without the containing div and ul tags and the generated HTML should look exactly like the previous wp_list_pages and wp_page_menu functions in our previous lesson.

Better Menu Markup

The difference here of course is that we can go in at any time and add, remove or modify any of the menu items on the fly without changing any code. And here’s our result.

So Now that we’ve got the basics covered lets put this baby through its paces a bit.


Picking up the Pace!

What we want to do as an exercise is create two Custom Menus which we will place into different locations. One in the standard position, below the header, and another in the top right side of the header.


Step 5: Registering two New Custom Menus

Using the method we’ve just gone through, I’m going to register two menu locations. Arrays are your friends.

<?php register_nav_menus(
	array(
		'top_header_menu'			=> 'Top Header: Menu at the very top of the header',
		'bottom_header_menu'		=> 'Bottom Header: Menu Below header Banner' )
	);
?>

It’s the same as using the following two lines of code:

<?php register_nav_menu('top_header_menu','Top Header: Menu at the very top of the header'); ?>

<?php register_nav_menu('bottom_header_menu','Bottom Header: Menu Below header Banner'); ?>

Just much neater and without repeating the register_nav_menu function, instead we use register_nav_menus.

Notice the "s" at the end of our function used to register more than one menu

I’ve registered two menus, ‘top_header_menu’ and ‘bottom_header_menu’. We’ll focus on just one of them for now, ‘bottom_header_menu’, which we’ll be putting in place of our existing wp_page_menu code.

The code to register these menus contains:

  • the name of the menu location as we will refer to it in code when calling it for placement in the theme
  • the description of the menu which we will see reflected in the dashboard admin area where we assign menus we build to locations.

This will help us know where we’re placing each menu. Now as we did earlier with our initial single primary menu which we created as a test, let’s create, Header Bottom and Header Top via Appearance > Menus and add some pages, preferably different pages to each one. I’ve got some default ones from my demo content generator.

We’ve registered them, built them and added them to locations so now we can place them into our theme.


Step 6: Extending the Placement Code

Because we’ve created two custom menus, we’re gonna need a little more than the default placement code to put into our theme so we can associate each location in the theme with a location registered via the menu registration function. We will need to add an additional parameter to the wp_nav_menu() function.

The Theme Location Parameter.

'theme_location' => '$menu_name'

The parameter ‘theme_location’, which should have a value of the name of the theme location we want to connect this area of our theme with. The theme’s location name should not have spaces in it, as it will be used within the functions codes which require no spaces. The name should be exactly the same as the name specified when registering the menu location.

<?php wp_nav_menu(
	array(
		'theme_location'  => 'bottom_header_menu'
	));
?>

Alternatively we could use the ‘menu’ parameter which explicitly fetches an already built menu from the menu builder.
The value for this parameter should be either the built menu’s Name, Slug or ID. Example below.

<?php wp_nav_menu(
	array(
		'menu'				=> 'Header Bottom'
	));
?>

These two options should not be used together as they will inevitably cancel each other out at some point considering the one pulls a menu based on it being assigned to a location, and the other pulls a menu based on the menu’s name. Some thought needs to go into choosing one or the other.

With ‘theme_location’ parameter, it would be possible to reassign menus to different locations, whereas with the ‘menu’ parameter we are restricted to only that specific menu being pulled into the coded area in the theme.

Let’s use the ‘theme_location’ parameter for now, seeing we will be registering two menus, which we might want to switch between the two locations. I’ll add in the three parameters we dealt with earlier as well to keep it all consistent and ready to display correctly.

<?php wp_nav_menu(
	array(
		'theme_location'	=> 'bottom_header_menu'
		'container'       	=> 'div',
		'container_id'    	=> 'menu',
		'menu_class'      	=> 'bottom-menu-list'
	));
?>

Which then takes the following menu we’ve built

Which results in the following which looks identical to what our initial code generated.

Menu One PLaced

Step 7: Placing the Second Menu

Now for that second menu which we registered and named ‘top_header_menu’.

We’re going to place a menu inside our header area, floating to the top right. We’ll use the same type of code for placing the first menu but changing the theme location. This will facilitate us to manage two separate lists of links. For example the top header menu could contain some generic links like contact, site map and the like.

We’ll use almost exactly the same code as we did with the first menu, changing the location name to reflect the name we used in registering the top menu. We’ll also give it unique container ID and menu ul class. You’ll notice an additional parameter at the end of this list. It’s the parameter to configure what type of fallback menu we’d like to use.

A fallback menu is one which appears when no menu has been assigned to the location yet. The default fallback method is wp_list_pages(), which will create a menu from all of the pages which exist in the site currently. This is not always ideal, though it may help in cases where layout or styling depend on a menu being present in certain themes. In the case of our Top Right menu, we don’t want anything to appear when no menu has been assigned, so that adding this menu is only optional, but not having it won’t cause breakages. To do this we specify the value to be false.

<?php wp_nav_menu(
	array(
		'theme_location'		=> 'top_header_menu',
		'container'				=> 'div',
		'container_id'			=> 'top-menu',
		'menu_class'      		=> 'top-menu-list',
		'fallback_cb'			=> 'false'
	));
?>

This code will be placed within the Header div, below the site name and description.

CSS already exists in the theme to position it top right in the header. I’ve included the CSS for the menus at the end of this Lesson.

Final 2 Menus

That’s the final result


Step 8: Fixing the Code for older WP

What we’ve done so far with the code for registering the menu functionality is very basic and on its own could be problematic. In some cases where your theme might be used on older versions of WordPress which do not support custom menus, you’d end up with errors. We need to add a layer to make the registration code backward compatible in the event that our theme is installed on older versions of WordPress.

Starting with the menu registration code we used for the two menus

<?php register_nav_menus(
	array(
		'top_header' => 'Menu at the very top of the page',
		'bottom_header' => 'Menu Below header Banner' )
	);
?>

We’ll wrap this with a conditional argument, which will first check if the current version of WordPress supports registration of menus. It’s checking if a function called register_nav_menus exists. If it does, the register_nav_menus function will be executed, if not the conditional argument will end with an endif. We’ll be going through conditional arguments in much more detail a little later in on in this series.

Take care to use a colon at the end of the first part of the if function, and a semi colon after the endif.

<?php  if(function_exists('register_nav_menus')) : ?>
	
    <?php register_nav_menus(
		array(
			'top_header' => 'Menu at the very top of the page',
			'bottom_header' => 'Menu Below header Banner' )
		);
	?>

<?php endif; ?>

For more detail on conditional or if statements in the mean time, view this tutorial – PHP for WordPress – Mastering Conditional Statements & Tags or the following page on the WordPress codex – codex.wordpress.org/Conditional_Tags

Much more solutions exist for Custom Menu registration, but this snippet will cover you in the vast majority of cases without turning your brain into mush. I hope.

Making Sure the Placement Code Degrades as well

We need to make sure that we still have a functional theme in cases where the custom menu functionality does not exist. We need to add an additional conditional statement to our placement code (wp_nav_menu). There are a few levels to this so pay close attention. If we don’t add this extra level we’ll end up with users of Pre 3.0 versions of WordPress getting nasty errors when loading this theme. You’ll end up with users on old WordPress threatening to tar and feather you in the street, so best you get this part right.

1. Our placement code as it was previously

<?php wp_nav_menu(
	array(
		'theme_location'		=> 'top_header_menu',
		'container'				=> 'div',
		'container_id'			=> 'top-menu',
		'menu_class'      		=> 'top-menu-list',
		'fallback_cb'			=> 'false'
	));
?>

To which we will add a similar conditional argument

<?php  if(function_exists('wp_nav_menu')) : ?>

	<?php wp_nav_menu(
		array(
			'theme_location'		=> 'top_header_menu',
			'container'				=> 'div',
			'container_id'			=> 'top-menu',
			'menu_class'      		=> 'top-menu-list',
			'fallback_cb'			=> 'false'
		));
	?>

<?php endif; ?>

On its own this would mean that a site running older versions of WordPress would just display nothing. We therefore have to add an extra argument to this conditional statement so that when the answer to the if(function_exists(‘wp_nav_menu’) comes back with a NO (meaning no the function does not exist), we can add in a fallback menu which works in WordPress pre 3.0. Here’s an outline.

<?php  if(function_exists('wp_nav_menu')) : ?>

	// we'll place the custom menu code here if the function does exist

<?php else: ?>

	// we'll place the fallback menu code here if not

<?php endif; ?>

FYI, Text which follows // withiin PHP code will not get executed or echoed and acts like comments within the code!

And with all the code string together

<?php  if(function_exists('wp_nav_menu')) : ?>

	<?php wp_nav_menu(
		array(
			'theme_location'		=> 'top_header_menu',
			'container'				=> 'div',
			'container_id'			=> 'top-menu',
			'menu_class'      		=> 'top-menu-list',
			'fallback_cb'			=> 'false'
		));
	?>

<?php else: ?>

    <div class="menu">
	    <ul>
	    	<?php wp_list_pages('title_li=&depth=0'); ?>
	    </ul>
    </div>

<?php endif; ?>

This allows us to fall back to an older style menu should the version of WordPress we’re using not support registration of custom menus.


Styling the Menus

In order to cater for all the variations which we’ve included for our menus, including the additional top right menu and the fallback menu which the placement code generates, I’ve included a mix of CSS selectors to cover all.
We’ve essentially got 3 main containers which will house the standard, top right and fallback menus.

  • Standard – #menu
  • Top Right – #top-menu
  • Fallback – .menu

The styles below can be found between lines 100 and 184 of the style.css file

/* ========================================================== Menu Styles ======= */

#menu, .menu, #top-menu {
	height: 30px;
	background-color:  #0099CC;
	display: block;
	padding: 10px 0 0 25px;
	border-bottom: 1px #698181 solid;
	border-top: 1px #698181 solid;
	font-family: "Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana,sans-serif;
}

#menu ul,
.menu ul,
#top-menu ul
 {
	float: left;
	display: block;
	margin: 0 25px 0 0;
	padding: 0;
}

#menu ul li,
.menu ul li,
#top-menu ul li
 {
	float: left;
	margin: 0 16px 0 0;
	width: auto;
	list-style: none;
	position:relative;
}

#menu ul li a,
.menu ul li a,
#top-menu ul li a
{
	color: #fff;
	text-decoration: none;
}

#menu li a:hover,
.menu li a:hover,
#top-menu ul li a:hover
{
	color: #9FF;
	text-decoration: underline;
}

#menu ul li ul.children,
#menu ul li ul.sub-menu,
.menu ul li ul.children,
#top-menu ul li ul.sub-menu
 {
	display:none;
}

#menu ul li ul.children li,
.menu ul li ul.children li,
#menu ul li ul.sub-menu li,
#top-menu ul li ul.sub-menu li
 {
	float:none;
}

#menu ul li:hover ul.children,
.menu ul li:hover ul.children,
#menu ul li:hover ul.sub-menu,
#top-menu ul li:hover ul.sub-menu
 {
	display:block;
	position:absolute;
	top:20px;
	margin: 0 16px 0 0;
	width: auto;
	list-style: none;
	background-color:#999;
}

#top-menu {
position:absolute;
	top: 0;
	right:0;	
}

A Quick Wrapup

  1. Create a functions file to register Custom Menus
  2. Create Menus via Appearance > Menus
  3. Insert Menu Placement Code
  4. Ensure menus point to the desired locations or menu names
  5. Ensure HTML being generated coincides with your menu CSS
  6. Ensure Registration Code does not break older WP
  7. Ensure your placement code does not break older WP

Next Up – Dynamic Sidebars Followed by The Loop – Stay Tuned!


Other parts in this series:WordPress Theme Development Training Wheels: Day TwoWordPress Theme Development Training Wheels: Day Four
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://brothemes.com Fejér Roland

    Very useful article, thanks Nur Ahmad Furlong :)

  • http://cssrockstar.com matt

    Do you really think that we need to code for older versions of WordPress? What reasons would someone have to not upgrade?

    • http://www.wpbedouine.com wpbedouine

      Sometimes when releasing themes for public use people using older versions of WordPress end up installing your theme. Not everyone upgrades immediately and sometimes some people have been found using quite old versions.

      It’s probably not that widespread but in some cases it helps to have fallbacks. In any case it’s up to you what you support for your needs.

  • http://a7web.com Aaron Holbrook

    One thing to keep in mind so that beginners don’t have problems with trailing whitespaces (i.e. the functions.php file) is to only have an opening php tag and not a closing one.

    <?php
    // code here
    // etc
    // etc

    • http://realita.org Martin

      god bless you, many tanks

  • Ross

    Can I get conformation on NOT needing a php closing tag, in functions.php file.
    Thanks.

    • Japh Thomson
      Staff

      Correct! You don’t need a closing PHP tag, assuming you don’t have any HTML following.

      :)

      • http://www.nomad-one.com nomadone

        Correct, the closing part of the php is not needed. I have however found that for beginners introducing concepts which seasoned PHP developers take for granted might not always be beneficial in the early stages.

        Getting users to become accustomed to always closing php code as a general practice is something important, just like when teaching beginners HTML< teaching them to close tags and to abserve correct nesting needs re-enforcement.

        I have taught this subject in physical classroom many times and I see common mistakes repeated over and over. With WordPress, there are tons of approaches, especially for seasoned developers, bu not all those approaches are practical or necessary to teach beginners immediately.

        Also, coding conventions need to be taught in stages, it's absolutely impossible to teach every coding convention used in 1 tutorial, and I'm not teaching PHP dev from the ground up so I hope you guys will understand if I leave 1 or 2 things out for starters.

  • Ricardo Ribeiro

    Glad to see you choose “casa da musica” for the tutorial thumbnail. It´s a nice building right next to me here in Portugal! :) Also, nice tutorial!.

  • http://www.ellahworks.com Rowela Alzona

    I really love ALL your posts! and tuts….!

  • http://smartwebworker.com Pritam @ Smart Web Worker

    Nice tutorial for beginners. Fairly easy and quick. Of course, it will take lots of practice and understanding of PHP to turn a PRO.

  • http://realita.org Martin

    many thanks for this post :)

  • Pingback: WordPress Theme Development Training Wheels: Day Three

  • Matt

    Pretty good set of tutorials. However, there’s a LOT of stuff that needs to be more explicit for a beginner. In the last lesson I couldn’t manage to get the ul class=”children” part to work how it was supposed to. Where the heck was I supposed to put that code? In this lesson, I’m already getting stumped by “We can neaten up the registration code as we did with wp_list_pages and put the parameters into an array.”

    Where? In functions.php? Somewhere else?

    Why does register_nav_menu( ‘primary’, ‘Primary Menu’ ); have three spaces? Is this necessary? Why?

    With too many beginner tutorials you can go through the motions and not actually learn ANYTHING. I feel like you’ve put together a series that’s actually pretty good, but it’s still missing the most basic level of material that could truly make it relevant to somebody starting out.

    • http://www.nomad-one.com nomadone

      I Matt. I agree, starting off with WordPress development can be daunting and you require as much detail as possible.

      Regarding where to place the registration code. As specified in the tutorial, menu “registration” takes place within the functions.php file. That’s the only place you’ll actually register the menu. I was mentioning arrays with reference to the previous tutorial because I can’t cover array structures in every lesson that has an array, so going back to the previous lesson where we first encountered the array would help.

      Maybe you can explain what problem you encountered with ul class=”children” so I know what you mean

      Also I didn’t get your question about 3 spaces, are you talking about blank spaces within the code between the different parts?

  • salman

    Hi, really helpful material you guys posted here, however I am stuck on a little problem.

    I am using Twenty Ten theme, and I need to insert a link to one of the , widgets ‘custom menu’ titles.
    In the widgets, in the primary widgets area, I have two custom menus, each of which shows a different menu. For each custom menu, I have to choose a title. I want to insert a hyperlink, to the title so that its clickable.

    I did try to link all the material, on this page to it, but I didnt find any hint.
    Would really appreciate if any one of you can help.

    • http://www.nomad-one.com nomad-one

      Hi Salman, I’m not sure I fully understand what you want to achieve. Where must the link appear? Can you give some more detail? Do you have a live page you are referring to?

  • http://www.toledotrade.com/training/ Lane

    I must have missed something. I have my menu working but, my pages do not change? Every page shows my static index.php file content that I uploaded.
    Is there a place were we pull dynamic content ot the middle column div that I missed?
    Thanks

    • http://www.nomad-one.com nomad-one

      @Lane, at this stage of the progress into our learning theme, contents have not been given their dynamic code yet, we’ve only focused on basic theme setup and menus and very soon the sidebars tut will be up. Once those are up we’ll get into what is Called The Lopp, which deals with all the content display stuff. Stay tuned!

      You could take a look at – http://wp.tutsplus.com/tutorials/theme-development/a-beginners-guide-to-the-wordpress-loop/ in the mean time, though I plan to do a much more from scratch lesson on this for the absolute newbie.

  • Pingback: WordPress Theme Development Training Wheels: Day Three | 備忘録

  • Andy

    When will you post more lessons, I need to learn as much, your screenshots and explanation has been very helpful but this lesson seemed daunting, so I made functions.php and added register_nav_menu, and with multiple Theme locations, I need to decide which one I need to turn on by that parameter: theme_location = “bottom_header” in the wp_nav_menu() function, and will you be putting up more tutorials very soon, of all the sites (including from WordPress.org), your WP custom theme development tutorials are the best.

  • Pingback: WordPress Theme Development Training Wheels: Day Three After having dealt with manually coding va… | 備忘録

  • Tiikaay

    Hi!

    Love you tuts, I have learnt A LOT from you guys.
    But this time, I can’t get it to work. .
    I was able to register the nav menu, no problem there, but it doesn’t show up. :(
    I called it with: <?php wp_nav_menu( array( ‘sort_column’ => ‘menu_order’, ‘container_class’ => ‘menu-header’ ) ); ?>
    Please help

  • Lauren

    I believe in there is an error in your final code example in Step 2 – do you mean to show an example of using an array with , which accepts theme_location as a parameter and allows the use of an array (while does neither)?

    • Lauren

      That should read “do you mean to show an example of using an array with <?php wp_nav_menu(); ?>, which accepts theme_location as a parameter and allows the use of an array (while <?php register_nav_menu(); ?> does neither)?”

  • Surendra

    Help! Menu under appearance is now showing in 3.3.1 admin.

  • Pingback: Understanding the Walker Class | Wptuts+

  • Pingback: Understanding the Walker Class | Wordpress Webdesigner

  • Pingback: Understanding the Walker Class | Shadowtek Hosting and Design Solutions

  • Pingback: My Stream | Understanding the Walker Class | My Stream

  • Pingback: Understanding the Walker Class | Wordpress Sifter

  • Pingback: Understanding the Walker Class

  • http://www.mylifeisagarden.com tom

    Hi

    thanks for putting this together.

    I tried to input this code

    ‘bottom_header_menu’
    ‘container’ => ‘div’,
    ‘container_id’ => ‘menu’,
    ‘menu_class’ => ‘bottom-menu-list’
    ));
    ?>

    And it did not work – then I noticed it is missing a comma

    ‘bottom_header_menu’
    ‘container’ => ‘div’,
    ‘container_id’ => ‘menu’,
    ‘menu_class’ => ‘bottom-menu-list’
    ));
    ?>

    Then, it worked.

    Really glad I could work it out myself! Big step.

    • tom

      I checked and my comma is no there, I prob commented it out lol! (I just checked and I did comment it out!)

      ‘bottom_header_menu’

      needs t be

      ‘bottom_header_menu’,

      Sorry I am too lazy to post it in a code display app.

  • http://webawesomeness.com/ John

    Loving your tutorials, very good work! However I did notice an error in Step 2. The code should read

    ‘bottom_header’
    ));
    ?>

    i.e “menus” and not “menu”

    • http://webawesomeness.com/ John

      Sorry my code was stripped, I meant to say the “register_nav_menu” in the last part of Step 2 should read “register_nav_menus” instead.

  • Geejayz

    I’m using an install of wordpress 3.4.1 and I get the following error when I introduce the functions.php file into the code;

    Warning: Cannot modify header information – headers already sent by (output started at /home/busin73/public_html/mysite/wp-content/themes/training-wheels-0.0/functions.php:3) in /home/busin73/public_html/mysite/wp-includes/option.php on line 563

    (I’ve changed my url location to mysite – other than that it’s the exact error message).

    To prove I hadn’t done anything wrong, I deleted everything and it in it’s place uploaded the contents of your resources.zip file. I get the same error message.

    Any ideas how to track down the problem – is this because I’m using 3.4.1 and you were using 3.2.1

  • Geejayz

    In your resources file, there seems to be a colon instead of a semi-colon in the first line.
    When I replace it I get this now instead;

    Parse error: syntax error, unexpected T_ENDIF in /home/busin73/public_html/mysite/wp-content/themes/training-wheels-0.0/functions.php on line 10

    The if and endif requirements are not mentioned in your tutorial above – however that doesn’t explain how I got the error on my own initially as I was copying the code in rather than using your resources file. I’ll try to retrace my steps back through the code again.

  • Geejayz

    OK, scratch that last comment (I’m obviously more tired than I thought). I’ve just seen the explanation for this in Step 8 above.
    It seems whenever I add in that conditional argument in Step 8 it causes the php code error.

    I also seem to have an issue (including your final test code) with the fallback menu. Basically, I want a theme that doesn’t require the user to set up the custom menu before it looks good. The code above seems to throw in an unordered menu with no styling until a menu is created.

    The issue seems to be partially explained here;
    http://wordpress.stackexchange.com/questions/891/wp-nav-menu-custom-container-and-container-id

    I suspect I need some other form of conditional argument that says if I have not set up a custom navigation menu that it should default to something else.

  • Geejayz

    I’ve been able to solve the php errors by replacing your functions.php code with this;

    <?php  if(function_exists('register_nav_menus')) {
    		register_nav_menus(
    			array(
    				'top_header' => 'Menu at the very top of the page',  
    				'bottom_header' => 'Menu Below header Banner' )
    			);  
    }
    ?>
    

    Still working on (need help with) the menu appearance.

  • Nick

    Hiya, thanks for the tutorial!

    I have a question, when adding in the <?php wp_nav_menu(

    I seem to have lost depth, I have added subpages via the menu builder and drop downs work fine with the 'pages' function.

    I have tried various things including adding a depth to the array (although I know '0', is the default), but this creates a error.

    Do you know what has gone wrong?

    Thanks
    Nick

  • romuloctba

    Dude, you are awesome! Thanks for this series of tuts. I didn’t put in pratice, but i’m really considering (meaning: i want to, i will) change my pratices.
    These recent days i’ve been looking for WP best pratices, this site is helping me a lot, yout tut also did.

    Thank you. I mean it ;P

  • http://www.kgnsoftech.com Rajnish Mishra

    I have studied all the tutorials on wordpress theme development and found it very useful can you help me development of wp plugin as we are using you rtutorials day by day thanks.

  • Toon

    This is one of the best tutorials I ever used.

    I almost panicked and cried getting into this wordpress business, you saved me.

    Thanks!