-
-
Save RussBrown00/684150ac1da971d01c9e019442626498 to your computer and use it in GitHub Desktop.
Statamic Modifiers to add trailing slashes to URLs
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 | |
namespace App\Modifiers; | |
use Statamic\Modifiers\Modifier; | |
class TrailingSlash extends Modifier { | |
public function index($value, $params, $context) { | |
// If URL is an full url or ends in /, do nothing | |
if (str_starts_with($value, "http") || str_ends_with($value, "/")) { | |
return $value; | |
} | |
// In production mode return ending slash | |
if ($_ENV["APP_ENV"] == "production") { | |
return "$value/"; | |
} | |
// return default value | |
return $value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment