Shortcodes for Oxygen's shortcode wrapper component to show/hide content based on if we're on an AMP page or not. For use with Oxygen Builder and AMP for WordPress plugin.
add_shortcode( 'show_if_amp', 'lit_show_on_amp_only' ); | |
/** | |
* Add a custom shortcode to show content if we're on amp page. | |
* | |
* Sample usage: [show_if_amp]content[/show_if_amp] | |
* | |
* @param array $atts An associative array of attributes, or an empty string if no attributes are given. | |
* @param string $content The enclosed content. | |
* @return void|string Enclosed content for amp pages and non-amp pages | |
*/ | |
function lit_show_on_amp_only( $atts, $content = null ) { | |
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) { // if we're on amp page | |
return $content; // show the content. | |
} else { | |
return null; // show nothing. | |
} | |
} | |
add_shortcode( 'hide_if_amp', 'lit_hide_on_amp_only' ); | |
/** | |
* Add a custom shortcode to hide content if we're on amp page. | |
* | |
* Sample usage: [hide_if_amp]content[/hide_if_amp] | |
* | |
* @param array $atts An associative array of attributes, or an empty string if no attributes are given. | |
* @param string $content The enclosed content. | |
* @return void|string Enclosed content for amp pages and non-amp pages | |
*/ | |
// Add Shortcode | |
function lit_hide_on_amp_only( $atts , $content = null ) { | |
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) { // if we're on amp page | |
return null; | |
} else { | |
return $content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment