Last active
February 19, 2025 22:33
-
-
Save PhrozenByte/247e65a6b11790fc304de78e105347db to your computer and use it in GitHub Desktop.
A simple Pico plugin to create redirection pages to arbitrary URLs.
This file contains hidden or 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 | |
/** | |
* Pico redirect plugin | |
* | |
* Adds a `Redirect` meta header to redirect to other URLs. The meta header | |
* supports URL substitution variables, namely %base_url%, %plugins_url%, | |
* %themes_url%, %assets_url% and %theme_url%. | |
* | |
* Example: | |
* | |
* ```markdown | |
* --- | |
* Redirect: %base_url%?sub/page | |
* --- | |
* ``` | |
* | |
* This plugin requires Pico 2.1+ and PHP 7.2. | |
* | |
* @author Daniel Rudolf | |
* @link http://picocms.org | |
* @license http://opensource.org/licenses/MIT The MIT License | |
* @version 0.0.1 | |
*/ | |
class PicoRedirect extends AbstractPicoPlugin | |
{ | |
const API_VERSION = 3; | |
public function onMetaHeaders(array &$headers) | |
{ | |
$headers['Redirect'] = 'redirect'; | |
} | |
public function onMetaParsed(array &$meta) | |
{ | |
if ($meta['redirect']) { | |
$redirectUrl = $this->getPico()->substituteUrl($meta['redirect']); | |
$redirectUrl = $this->getPico()->getAbsoluteUrl($redirectUrl, null, false); | |
$serverProtocol = $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1'; | |
header($serverProtocol . ' 302 Found'); | |
header('Location: ' . $redirectUrl); | |
exit(); | |
} | |
} | |
} |
Oh my theme already has that condition. In fact it was because of this condition, I searched the doc on hiding the page and came across the _ hiding method. Didn't know that it can be done using YAML frontmatter too. Thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@notakoder You can add
hidden: true
to your page's YAML Frontmatter. However, not all themes respect this header, but adding support for it is pretty easy ({% if not page.hidden %}
).