Skip to content

Instantly share code, notes, and snippets.

@billerickson billerickson/amp.php Secret
Created Jun 5, 2019

Embed
What would you like to do?
<?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
You can’t perform that action at this time.