Monday, June 29, 2015

Menuing

With out three page structure, we need to a way to navigate from the home page to the pages A and B. Luckily, WordPress provides a navigation menus feature that makes this easy: https://codex.wordpress.org/Navigation_Menus.

The first step is to add to functions.php:

functions.php
function register_my_menu() {
  register_nav_menu('header-menu',__('Header Menu'));
}
add_action( 'init', 'register_my_menu' );

note: The weird double-underscore is use for language, e.g., Spanish, translation if enabled.

Then we add the following just below the body tag in index.php.

index.php
<?php wp_nav_menu(array('theme_location' => 'header-menu')); ?>

Now as we update the menu in admin > Appearance > Menus, we can see the changes reflected on all of the pages.

Setting Up Permalinks

A quick visit to admin > Settings > Permalinks (e.g., setting it to Post name) will give one nice looking URLs.

Setting Up Breadcrumbs

This is essentially the "menu" for navigating back up the hierarchy of pages.

Here we use our first Wordpress Plugin; the one that we are using is called WordPress SEO  Use admin > Plugins to get this done and insert the following in index.php where one wants the breadcrumb to appear, e.g., just below the navigation menu.

index.php
<?php if (function_exists('yoast_breadcrumb')) {
  yoast_breadcrumb();
}?>

note: This plug-in serves a number other SEO purposes that we will address in a later post.

No comments:

Post a Comment