Created
August 19, 2016 14:57
-
-
Save brianlayman/b43e82e61b2fc67829cab6565684d839 to your computer and use it in GitHub Desktop.
trailingampit ensures a URL ends with a /amp/
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 | |
/** | |
* Ensures the passed text, presumably an url, ends with '/amp/' | |
*/ | |
if ( !function_exists( 'trailingampit' ) ) { | |
function trailingampit( $string ) { | |
return untrailingampit( $string ) . 'amp/'; | |
} | |
} | |
/** | |
* Ensures the passed text, presumably an url, does not end with 'amp/' or 'amp' | |
*/ | |
if ( !function_exists( 'untrailingampit' ) ) { | |
function untrailingampit( $str ) { | |
$result = preg_replace( '/(amp|amp\/)$/', '', $str ); | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment