Skip to content

Instantly share code, notes, and snippets.

@jacmaes
Created February 14, 2020 14:43
Show Gist options
  • Save jacmaes/68eb9f6ac6a5bce73b609b4a49af0005 to your computer and use it in GitHub Desktop.
Save jacmaes/68eb9f6ac6a5bce73b609b4a49af0005 to your computer and use it in GitHub Desktop.
PW pagination in <head> #pw #php
// From Kreativan's gist: https://gist.github.com/kreativan/bddcfa1c923f563d968ff40f2fb4e32e
<?php
//-----------------------------------------------------------------------
// Add rel="next" and rel="prev" tags for pagination in head section
//-----------------------------------------------------------------------
$wire->addHookAfter('Page::render', function(HookEvent $event) {
$page = $event->object;
if($page->template == 'admin') return;
$tags = '';
$config = wire('config');
if($config->urls->httpNext) {
$tags .= "<link rel='next' href='{$config->urls->httpNext}'>";
}
if($config->urls->httpPrev) {
$tags .= "<link rel='prev' href='{$config->urls->httpPrev}'>";
}
$event->return = str_replace("</head>", $tags . "</head>", $event->return);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment