Last active
May 9, 2022 16:35
-
-
Save westonruter/b22cfae13f0862d5b9716c776c60f882 to your computer and use it in GitHub Desktop.
Basic plugin which adds a nav menu to Reader mode templates in the AMP plugin. When in Reader mode, upon activation a new “AMP Reader Sidebar” nav menu location is available for assigning the desired nav menu. Temporary until closed: https://github.com/ampproject/amp-wp/issues/2044
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
<?php | |
/** | |
* Header bar template part. | |
* | |
* This is a forked version of the header-bar.php in the AMP plugin. | |
* | |
* @link https://github.com/ampproject/amp-wp/blob/e63d2c3034d079f1a1b5bb2f0a2d1e0a221cadb9/templates/header-bar.php | |
* @package AMP_Reader_Nav_Menu | |
*/ | |
namespace AMP_Reader_Nav_Menu; | |
/** | |
* Context. | |
* | |
* @var \AMP_Post_Template $this | |
*/ | |
?> | |
<header id="top" class="amp-wp-header"> | |
<div> | |
<?php if ( has_nav_menu( NAV_MENU_LOCATION ) ) : ?> | |
<button id="toggleNavMenu" type="button" on="tap:navMenu.open" aria-label="<?php esc_html__( 'Open nav menu', 'amp-reader-nav-menu' ); ?>">☰</button> | |
<?php endif; ?> | |
<a href="<?php echo esc_url( $this->get( 'home_url' ) ); ?>"> | |
<?php $site_icon_url = $this->get( 'site_icon_url' ); ?> | |
<?php if ( $site_icon_url ) : ?> | |
<amp-img src="<?php echo esc_url( $site_icon_url ); ?>" width="32" height="32" class="amp-wp-site-icon"></amp-img> | |
<?php endif; ?> | |
<span class="amp-site-title"> | |
<?php echo esc_html( wptexturize( $this->get( 'blog_name' ) ) ); ?> | |
</span> | |
</a> | |
<?php $canonical_link_url = $this->get( 'post_canonical_link_url' ); ?> | |
<?php if ( $canonical_link_url ) : ?> | |
<?php $canonical_link_text = $this->get( 'post_canonical_link_text' ); ?> | |
<a class="amp-wp-canonical-link" href="<?php echo esc_url( $canonical_link_url ); ?>"> | |
<?php echo esc_html( $canonical_link_text ); ?> | |
</a> | |
<?php endif; ?> | |
</div> | |
</header> | |
<?php if ( has_nav_menu( NAV_MENU_LOCATION ) ) : ?> | |
<?php | |
printf( | |
'<amp-sidebar id="navMenu" layout="nodisplay" side="%s">%s</amp-sidebar>', | |
esc_attr( is_rtl() ? 'right' : 'left' ), | |
wp_nav_menu( | |
[ | |
'theme_location' => NAV_MENU_LOCATION, | |
'echo' => false, | |
'depth' => 1, | |
] | |
) | |
); | |
?> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @westonruter thank you for this solution, it worked perfectly in my project.