Trying to create navigation menu in Wordpress theme


Hello everyone,
I am trying to create my own theme in Wordpress. I am trying to create in functions.php the navigation menu for my categories and they are 4 in total. Additionally I want to display a navigative link in the footer as well but it will have three different links. Any help will be huge. Thanks in advance

In my functions.php file I have:


	function theme_setup(){

		register_nav_menus(array('menu1'=>'Primary Menu','menu2'=>'Secondary Menu'));



In my header.php file I have:

<?php ?>
<!DOCTYPE html>
<html lang="en">
	<meta charset="UTF-8">

	<?php wp_head(); ?>

		<img src="<?php header_image(); ?>" alt="">

		<h1><a href="<?php echo bloginfo('wpurl');?>"><?php echo bloginfo( 'name' ); ?></a></h1>

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

And in my footer.php file I have:

<?php  ?>

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


Are you building entirely from scratch or using underscores or a similar starter theme?


Hello @MotiMo,
How are you?
I am creating it from scratch


Hello! I’ve been better but that aside. If you are creating it completely from scratch then I would definitely recommend considering using Underscores, Sage or another starter theme, if not as the base then at least as a guide to help you organize your own theme.


Why are you creating a nav menu from scratch? Use the wordpress menu, follow the process other themes use.


Actually we have been instructed to create right from scratch. Its ok I have figured it out :slight_smile:
Thank You



Instructed as in via a professor? Just wondering why you would use wordpress and not leverage its abilities. Seems, well it is, stupid.


Yes, our professor asked us to create a theme from scratch and create customized nav menus (registering them)


I am going to tell you to forget whatever they teach you when you leave then.

WordPress is simple overall, but it is because everyone follows the same rules and practices. Themes are easy, but making a nav menu in the theme is a horrid practice for a few reasons, primarily of which, when the user switches the theme, they loose access to those pages. Learning this, you should take a theme and see how it works, them modify it so you can learn what it does. Considering the pages are built thru the database, a custom nav that sits outside of that will break the process.


Oh I see. Ok :slight_smile: I will learn the way you have suggested. Yes, I noticed many times u have suggested so far the coding practices suggested by him is bad


Whaaaat!? haha Yes I will echo what Astonecipher says here. This is not really a practical or smart way to learn WP. I would definitely suggest working with a “starter” or base theme as I mentioned above. Those are themes that are made to work as a framework for customization, but they are basically a skeleton of a theme that you can learn from and customize as you like. IMHO it is a better approach to learn from a properly set up and lean theme, than it is to try and learn how to create an entire theme from scratch. Just my 2cents, Good Luck with the class~


Thank You :slight_smile: