Skip to content

Commit cf30fe7

Browse files
committed
Initial commit.
1 parent 446e1dd commit cf30fe7

File tree

6 files changed

+280
-2
lines changed

6 files changed

+280
-2
lines changed

README.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,71 @@
1-
genesis-header-nav
2-
==================
1+
# Genesis Header Nav
32

43
WordPress plugin that registers a menu location and displays it inside the header for a Genesis Framework child theme.
4+
5+
## Description
6+
7+
The default method of getting a menu to appear in the top right of a site using a child theme of the Genesis Framework, is to add a create a menu in Appearance -> Menus, and then place a Custom Menu widget in the Header Right widget area. While this works, it produces markup as seen in screenshot 1, and which has the following problems:
8+
9+
* Since the menu is output from a widget, you end up with all of the extraneous widget and widget area markup - in a child theme with HTML5 support, that's the widget area `aside`, the widget `section`, and the widget wrap `div`. In themes without HTML support, it's three levels of `div` elements instead. Not only is this more DOM elements to render (performance), but all markup in the site header is pushing the real page content further down the source; search engines apparently put higher value on content at the top of the source (which is why Genesis ensures primary and secondary sidebars come lower in the source than the main content, irrespective of where they are displayed on screen).
10+
* In HTML5 themes, what could be a site's main navigation is wrapped in an `aside` element. It's not known whether this has any impact on SEO. Theoretically at least, search engines may put less value on navigation found in an `aside` or otherwise treat it differently.
11+
12+
This plugin registers a new menu location called Header and, if a menu is assigned to it, displays it before the Header Right area. If you don't have any widgets in the Header Right area, then Genesis ensures that none of that widget area markup is output, so you end up with code like screenshot 2. If you do want a widget in the Header Right area, that's fine - it can be positioned and styled as you want, without negatively affecting the navigation menu as well.
13+
14+
The plugin should work with all Genesis child themes, though you may need to add styles to position the output in the traditional place of top right, e.g.:
15+
16+
~~~css
17+
.nav-header {
18+
float: right;
19+
text-align: right;
20+
width: 50%;
21+
}
22+
~~~
23+
24+
## Screenshots
25+
26+
![Screenshot of markup using Custom Menu widget](https://raw.github.com/GaryJones/genesis-header-nav/master/assets/screenshot-1.png)
27+
_Screenshot 1: Markup using Custom Menu widget._
28+
29+
---
30+
31+
![Screenshot of markup using this plugin](https://raw.github.com/GaryJones/genesis-header-nav/master/assets/screenshot-2.png)
32+
_Screenshot 2: Markup using this plugin._
33+
34+
## Requirements
35+
* WordPress 3.0
36+
* Genesis 2.0
37+
38+
## Installation
39+
40+
### Upload
41+
42+
1. Download the latest tagged archive (choose the "zip" option).
43+
2. Go to the __Plugins -> Add New__ screen and click the __Upload__ tab.
44+
3. Upload the zipped archive directly.
45+
4. Go to the Plugins screen and click __Activate__.
46+
47+
### Manual
48+
49+
1. Download the latest tagged archive (choose the "zip" option).
50+
2. Unzip the archive.
51+
3. Copy the folder to your `/wp-content/plugins/` directory.
52+
4. Go to the Plugins screen and click __Activate__.
53+
54+
Check out the Codex for more information about [installing plugins manually](http://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation).
55+
56+
### Git
57+
58+
Using git, browse to your `/wp-content/plugins/` directory and clone this repository:
59+
60+
`git clone git@github.com:GaryJones/genesis-header-nav.git`
61+
62+
Then go to your Plugins screen and click __Activate__.
63+
64+
## Usage
65+
66+
Once activated, head to Appearance -> Menus. Create a menu as usual, and assign it to the Header menu location. The plugin does the rest.
67+
68+
## Credits
69+
70+
Built by [Gary Jones](https://twitter.com/GaryJ)
71+
Copyright 2013 [Gamajo Tech](http://gamajo.com/)

assets/screenshot-1.png

21.9 KB
Loading

assets/screenshot-2.png

16.9 KB
Loading

class-genesis-header-nav.php

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
/**
3+
* Genesis Header Nav
4+
*
5+
* @package GenesisHeaderNav
6+
* @author Gary Jones <gary@garyjones.co.uk>
7+
* @license GPL-2.0+
8+
* @link https://github.com/GaryJones/genesis-header-nav
9+
* @copyright 2013 Gary Jones, Gamajo Tech
10+
*/
11+
12+
/**
13+
* Plugin class.
14+
*
15+
* @package GenesisHeaderNav
16+
* @author Gary Jones <gary@garyjones.co.uk>
17+
*/
18+
class Genesis_Header_Nav {
19+
20+
/**
21+
* Instance of this class.
22+
*
23+
* @since 1.0.0
24+
*
25+
* @var object
26+
*/
27+
protected static $instance = null;
28+
29+
/**
30+
* Initialize the plugin by setting localization, filters, and administration functions.
31+
*
32+
* @since 1.0.0
33+
*/
34+
private function __construct() {
35+
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
36+
add_action( 'genesis_setup', array( $this, 'register_nav_menu' ), 15 );
37+
add_action( 'genesis_header', array( $this, 'show_menu' ), 8 );
38+
add_filter( 'body_class', array( $this, 'body_classes' ), 15 );
39+
}
40+
41+
/**
42+
* Return an instance of this class.
43+
*
44+
* @since 1.0.0
45+
*
46+
* @return object A single instance of this class.
47+
*/
48+
public static function get_instance() {
49+
// If the single instance hasn't been set, set it now.
50+
if ( null == self::$instance ) {
51+
self::$instance = new self;
52+
}
53+
54+
return self::$instance;
55+
}
56+
57+
/**
58+
* Load the plugin text domain for translation.
59+
*
60+
* @since 1.0.0
61+
*/
62+
public function load_plugin_textdomain() {
63+
$domain = 'genesis-header-nav';
64+
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
65+
66+
load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
67+
load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages' );
68+
}
69+
70+
/**
71+
* Register the menu location.
72+
*
73+
* @since 1.0.0
74+
*/
75+
public function register_nav_menu() {
76+
register_nav_menu( 'header', __( 'Header', 'genesis-header-nav' ) );
77+
}
78+
79+
/**
80+
* Display the menu.
81+
*
82+
* @since 1.0.0
83+
*/
84+
public function show_menu() {
85+
//* If menu is assigned to theme location, output
86+
if ( ! has_nav_menu( 'header' ) )
87+
return;
88+
89+
$class = 'menu genesis-nav-menu menu-header';
90+
if ( genesis_superfish_enabled() )
91+
$class .= ' js-superfish';
92+
93+
$args = array(
94+
'theme_location' => 'header',
95+
'container' => '',
96+
'menu_class' => $class,
97+
'echo' => 0,
98+
);
99+
100+
$nav = wp_nav_menu( $args );
101+
102+
//* Do nothing if there is nothing to show
103+
if ( ! $nav )
104+
return;
105+
106+
$nav_markup_open = genesis_markup( array(
107+
'html5' => '<nav %s>',
108+
'xhtml' => '<div id="nav">',
109+
'context' => 'nav-header',
110+
'echo' => false,
111+
) );
112+
$nav_markup_open .= genesis_structural_wrap( 'menu-header', 'open', 0 );
113+
114+
$nav_markup_close = genesis_structural_wrap( 'menu-header', 'close', 0 );
115+
$nav_markup_close .= genesis_html5() ? '</nav>' : '</div>';
116+
117+
$nav_output = $nav_markup_open . $nav . $nav_markup_close;
118+
119+
echo apply_filters( 'genesis_do_header_nav', $nav_output, $nav, $args );
120+
}
121+
122+
/**
123+
* Remove then conditionally re-add header-full-width body class.
124+
*
125+
* As well as just checking for something being in the header right widget area, or the action having something
126+
* hooked* in, we also need to check to see if the header navigation has a menu assigned to it. Only if all are
127+
* false can we* proceed with saying the header-full-width class should be applied.
128+
*
129+
* Function must be hooked after priority 10, so Genesis has had a chance to do the filtering first.
130+
*
131+
* @since 1.0.0
132+
*
133+
* @param array $classes Existing classes.
134+
*
135+
* @return array Amended classes.
136+
*/
137+
public function body_classes( array $classes ) {
138+
// Loop through existing classes to remove 'header-full-width'
139+
foreach ( $classes as $index => $class ) {
140+
if ( 'header-full-width' === $class ) {
141+
unset( $classes[$index] );
142+
break; // No need to check the rest.
143+
}
144+
}
145+
146+
// Do all the checks
147+
if ( ! is_active_sidebar( 'header-right' ) && ! has_action( 'genesis_header_right' ) && ! has_nav_menu( 'top' ) )
148+
$classes[] = 'header-full-width';
149+
150+
return $classes;
151+
}
152+
153+
}

genesis-header-nav.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Genesis Header Nav
4+
*
5+
* @package GenesisHeaderNav
6+
* @author Gary Jones <gary@garyjones.co.uk>
7+
* @license GPL-2.0+
8+
* @link https://github.com/GaryJones/genesis-header-nav
9+
* @copyright 2013 Gary Jones, Gamajo Tech
10+
*
11+
* @wordpress-plugin
12+
* Plugin Name: Genesis Header Nav
13+
* Plugin URI: https://github.com/GaryJones/genesis-header-nav
14+
* Description: Registers a menu location and displays it inside the header for a Genesis Framework child theme.
15+
* Version: 1.0.0
16+
* Author: Gary Jones
17+
* Author URI: http://gamajo.com/
18+
* Text Domain: genesis-header-nav
19+
* License: GPL-2.0+
20+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
21+
* Domain Path: /languages
22+
*/
23+
24+
// If this file is called directly, abort.
25+
if ( ! defined( 'WPINC' ) ) {
26+
die;
27+
}
28+
29+
require_once plugin_dir_path( __FILE__ ) . 'class-genesis-header-nav.php';
30+
31+
Genesis_Header_Nav::get_instance();

languages/genesis-header-nav.pot

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (C) 2013 Gary Jones, Gamajo Tech
2+
# This file is distributed under the GPL-2.0+.
3+
msgid ""
4+
msgstr ""
5+
"Project-Id-Version: Genesis Header Nav v1.0.0\n"
6+
"POT-Creation-Date: 2013-08-30 11:33:00+0000\n"
7+
"PO-Revision-Date: 2013-08-30 11:33:00+0000\n"
8+
"Report-Msgid-Bugs-To: https://github.com/GaryJones/genesis-header-nav/issues \n"
9+
"Last-Translator: Gary Jones <gary@garyjones.co.uk>\n"
10+
"Language-Team: English https://github.com/GaryJones/genesis-header-nav \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: 8bit\n"
14+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
15+
"X-Poedit-Basepath: .\n"
16+
"X-Poedit-Language: English\n"
17+
"X-Poedit-Country: United Kingdom\n"
18+
"X-Poedit-SourceCharset: utf-8\n"
19+
"X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
20+
"X-Poedit-Basepath: ../\n"
21+
"X-Poedit-Bookmarks: \n"
22+
"X-Poedit-SearchPath-0: .\n"
23+
"X-Textdomain-Support: yes"
24+
25+
#: class-genesis-header-nav.php:76
26+
msgid "Header"
27+
msgstr ""

0 commit comments

Comments
 (0)