justinwalsh/daux.io

Page specific meta description

Mark-H opened this issue · 2 comments

Is there a way to add page specific meta description, perhaps through front matter?

Found a way! In the markdown files:

---
title: 'Hello!'
description: 'Welcome to this awesome page.'
---

And in the layout/00_layout.php file of the theme:

<?php
$desc = $params->getCurrentPage()->getAttribute('description');
if (!empty($desc)) {
    echo '<meta name="description" content="' . htmlentities($desc, ENT_QUOTES, 'UTF-8') . '" />';
}
else {
    echo '<meta name="description" content="The official documentation for modmore extras." />';
}
?>

Exactly :D