Last active
February 12, 2021 03:52
-
-
Save wplit/3508c9dc9baa2f247d4dfb5a55e55a40 to your computer and use it in GitHub Desktop.
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.
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
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