-
-
Save billerickson/81dd463c78aae9d70b441a310a4d427f to your computer and use it in GitHub Desktop.
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 | |
/** | |
* AMP functionality | |
* | |
* @package EAStarter | |
* @author Bill Erickson | |
* @since 1.0.0 | |
* @license GPL-2.0+ | |
**/ | |
/** | |
* Is AMP? | |
* Conditional tag | |
*/ | |
function ea_is_amp() { | |
return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint(); | |
} | |
/** | |
* AMP Class | |
* | |
*/ | |
function ea_amp_class( $default, $active, $variable ) { | |
$output = ''; | |
if( ea_is_amp() ) { | |
$output .= ' [class]="' . $variable . ' ? \'' . $default . ' ' . $active . '\' : \'' . $default . '\'"'; | |
} | |
$output .= ' class="' . $default . '"'; | |
return $output; | |
} | |
/** | |
* AMP Toggle | |
* | |
*/ | |
function ea_amp_toggle( $variable = '', $disable = array() ) { | |
if( ! ea_is_amp() ) | |
return; | |
$settings = $variable . ': !' . $variable; | |
if( !empty( $disable ) ) { | |
foreach( $disable as $disable_var ) { | |
$settings .= ', ' . $disable_var . ': false'; | |
} | |
} | |
return ' on="tap:AMP.setState({' . $settings . '})"'; | |
} | |
/** | |
* AMP Nav Dropdown | |
* | |
*/ | |
function ea_amp_nav_dropdown( $theme_location = false, $depth = 0 ) { | |
$key = 'nav'; | |
if( !empty( $theme_location ) ) | |
$key .= ucwords( $theme_location ); | |
global $submenu_index; | |
$submenu_index++; | |
$key .= 'SubmenuExpanded' . $submenu_index; | |
if( 1 < $depth ) | |
$key .= 'Depth' . $depth; | |
return ea_amp_toggle( $key ) . ea_amp_class( 'submenu-expand', 'expanded', $key ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment