Skip to content

Instantly share code, notes, and snippets.

@RussBrown00
Created February 23, 2023 23:39
Show Gist options
  • Save RussBrown00/684150ac1da971d01c9e019442626498 to your computer and use it in GitHub Desktop.
Save RussBrown00/684150ac1da971d01c9e019442626498 to your computer and use it in GitHub Desktop.
Statamic Modifiers to add trailing slashes to URLs
<?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