-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,71 @@ | ||
genesis-header-nav | ||
================== | ||
# Genesis Header Nav | ||
|
||
WordPress plugin that registers a menu location and displays it inside the header for a Genesis Framework child theme. | ||
|
||
## Description | ||
|
||
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: | ||
|
||
* 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). | ||
* 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. | ||
|
||
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. | ||
|
||
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.: | ||
|
||
~~~css | ||
.nav-header { | ||
float: right; | ||
text-align: right; | ||
width: 50%; | ||
} | ||
~~~ | ||
|
||
## Screenshots | ||
|
||
 | ||
_Screenshot 1: Markup using Custom Menu widget._ | ||
|
||
--- | ||
|
||
 | ||
_Screenshot 2: Markup using this plugin._ | ||
|
||
## Requirements | ||
* WordPress 3.0 | ||
* Genesis 2.0 | ||
|
||
## Installation | ||
|
||
### Upload | ||
|
||
1. Download the latest tagged archive (choose the "zip" option). | ||
2. Go to the __Plugins -> Add New__ screen and click the __Upload__ tab. | ||
3. Upload the zipped archive directly. | ||
4. Go to the Plugins screen and click __Activate__. | ||
|
||
### Manual | ||
|
||
1. Download the latest tagged archive (choose the "zip" option). | ||
2. Unzip the archive. | ||
3. Copy the folder to your `/wp-content/plugins/` directory. | ||
4. Go to the Plugins screen and click __Activate__. | ||
|
||
Check out the Codex for more information about [installing plugins manually](http://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation). | ||
|
||
### Git | ||
|
||
Using git, browse to your `/wp-content/plugins/` directory and clone this repository: | ||
|
||
`git clone [email protected]:GaryJones/genesis-header-nav.git` | ||
|
||
Then go to your Plugins screen and click __Activate__. | ||
|
||
## Usage | ||
|
||
Once activated, head to Appearance -> Menus. Create a menu as usual, and assign it to the Header menu location. The plugin does the rest. | ||
|
||
## Credits | ||
|
||
Built by [Gary Jones](https://twitter.com/GaryJ) | ||
Copyright 2013 [Gamajo Tech](http://gamajo.com/) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?php | ||
/** | ||
* Genesis Header Nav | ||
* | ||
* @package GenesisHeaderNav | ||
* @author Gary Jones <[email protected]> | ||
* @license GPL-2.0+ | ||
* @link https://github.com/GaryJones/genesis-header-nav | ||
* @copyright 2013 Gary Jones, Gamajo Tech | ||
*/ | ||
|
||
/** | ||
* Plugin class. | ||
* | ||
* @package GenesisHeaderNav | ||
* @author Gary Jones <[email protected]> | ||
*/ | ||
class Genesis_Header_Nav { | ||
|
||
/** | ||
* Instance of this class. | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @var object | ||
*/ | ||
protected static $instance = null; | ||
|
||
/** | ||
* Initialize the plugin by setting localization, filters, and administration functions. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
private function __construct() { | ||
add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); | ||
add_action( 'genesis_setup', array( $this, 'register_nav_menu' ), 15 ); | ||
add_action( 'genesis_header', array( $this, 'show_menu' ), 8 ); | ||
add_filter( 'body_class', array( $this, 'body_classes' ), 15 ); | ||
} | ||
|
||
/** | ||
* Return an instance of this class. | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @return object A single instance of this class. | ||
*/ | ||
public static function get_instance() { | ||
// If the single instance hasn't been set, set it now. | ||
if ( null == self::$instance ) { | ||
self::$instance = new self; | ||
} | ||
|
||
return self::$instance; | ||
} | ||
|
||
/** | ||
* Load the plugin text domain for translation. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public function load_plugin_textdomain() { | ||
$domain = 'genesis-header-nav'; | ||
$locale = apply_filters( 'plugin_locale', get_locale(), $domain ); | ||
|
||
load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' ); | ||
load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages' ); | ||
} | ||
|
||
/** | ||
* Register the menu location. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public function register_nav_menu() { | ||
register_nav_menu( 'header', __( 'Header', 'genesis-header-nav' ) ); | ||
} | ||
|
||
/** | ||
* Display the menu. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public function show_menu() { | ||
//* If menu is assigned to theme location, output | ||
if ( ! has_nav_menu( 'header' ) ) | ||
return; | ||
|
||
$class = 'menu genesis-nav-menu menu-header'; | ||
if ( genesis_superfish_enabled() ) | ||
$class .= ' js-superfish'; | ||
|
||
$args = array( | ||
'theme_location' => 'header', | ||
'container' => '', | ||
'menu_class' => $class, | ||
'echo' => 0, | ||
); | ||
|
||
$nav = wp_nav_menu( $args ); | ||
|
||
//* Do nothing if there is nothing to show | ||
if ( ! $nav ) | ||
return; | ||
|
||
$nav_markup_open = genesis_markup( array( | ||
'html5' => '<nav %s>', | ||
'xhtml' => '<div id="nav">', | ||
'context' => 'nav-header', | ||
'echo' => false, | ||
) ); | ||
$nav_markup_open .= genesis_structural_wrap( 'menu-header', 'open', 0 ); | ||
|
||
$nav_markup_close = genesis_structural_wrap( 'menu-header', 'close', 0 ); | ||
$nav_markup_close .= genesis_html5() ? '</nav>' : '</div>'; | ||
|
||
$nav_output = $nav_markup_open . $nav . $nav_markup_close; | ||
|
||
echo apply_filters( 'genesis_do_header_nav', $nav_output, $nav, $args ); | ||
} | ||
|
||
/** | ||
* Remove then conditionally re-add header-full-width body class. | ||
* | ||
* As well as just checking for something being in the header right widget area, or the action having something | ||
* hooked* in, we also need to check to see if the header navigation has a menu assigned to it. Only if all are | ||
* false can we* proceed with saying the header-full-width class should be applied. | ||
* | ||
* Function must be hooked after priority 10, so Genesis has had a chance to do the filtering first. | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @param array $classes Existing classes. | ||
* | ||
* @return array Amended classes. | ||
*/ | ||
public function body_classes( array $classes ) { | ||
// Loop through existing classes to remove 'header-full-width' | ||
foreach ( $classes as $index => $class ) { | ||
if ( 'header-full-width' === $class ) { | ||
unset( $classes[$index] ); | ||
break; // No need to check the rest. | ||
} | ||
} | ||
|
||
// Do all the checks | ||
if ( ! is_active_sidebar( 'header-right' ) && ! has_action( 'genesis_header_right' ) && ! has_nav_menu( 'top' ) ) | ||
$classes[] = 'header-full-width'; | ||
|
||
return $classes; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* Genesis Header Nav | ||
* | ||
* @package GenesisHeaderNav | ||
* @author Gary Jones <[email protected]> | ||
* @license GPL-2.0+ | ||
* @link https://github.com/GaryJones/genesis-header-nav | ||
* @copyright 2013 Gary Jones, Gamajo Tech | ||
* | ||
* @wordpress-plugin | ||
* Plugin Name: Genesis Header Nav | ||
* Plugin URI: https://github.com/GaryJones/genesis-header-nav | ||
* Description: Registers a menu location and displays it inside the header for a Genesis Framework child theme. | ||
* Version: 1.0.0 | ||
* Author: Gary Jones | ||
* Author URI: http://gamajo.com/ | ||
* Text Domain: genesis-header-nav | ||
* License: GPL-2.0+ | ||
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt | ||
* Domain Path: /languages | ||
*/ | ||
|
||
// If this file is called directly, abort. | ||
if ( ! defined( 'WPINC' ) ) { | ||
die; | ||
} | ||
|
||
require_once plugin_dir_path( __FILE__ ) . 'class-genesis-header-nav.php'; | ||
|
||
Genesis_Header_Nav::get_instance(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright (C) 2013 Gary Jones, Gamajo Tech | ||
# This file is distributed under the GPL-2.0+. | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Genesis Header Nav v1.0.0\n" | ||
"POT-Creation-Date: 2013-08-30 11:33:00+0000\n" | ||
"PO-Revision-Date: 2013-08-30 11:33:00+0000\n" | ||
"Report-Msgid-Bugs-To: https://github.com/GaryJones/genesis-header-nav/issues \n" | ||
"Last-Translator: Gary Jones <[email protected]>\n" | ||
"Language-Team: English https://github.com/GaryJones/genesis-header-nav \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=2; plural=n != 1;\n" | ||
"X-Poedit-Basepath: .\n" | ||
"X-Poedit-Language: English\n" | ||
"X-Poedit-Country: United Kingdom\n" | ||
"X-Poedit-SourceCharset: utf-8\n" | ||
"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" | ||
"X-Poedit-Basepath: ../\n" | ||
"X-Poedit-Bookmarks: \n" | ||
"X-Poedit-SearchPath-0: .\n" | ||
"X-Textdomain-Support: yes" | ||
|
||
#: class-genesis-header-nav.php:76 | ||
msgid "Header" | ||
msgstr "" |