Mecha CMS

Mecha CMS blog and documentation.

Manual Post Excerpt

Table of Contents
  1. Usage 

Add manual post excerpt feature.

Hook::set('page.excerpt', function($content, $lot) {
    $s = Page::open($lot['path'])->get([
        'description' => null,
        'content' => null
    // Excerpt cropper does not exist, return the page description!
    // If page description is empty, return a fake excerpt generated by the page content!
    if (!$s['content'] || strpos($s['content'], '<!-- cut -->') === false) {
        return $s['description'] ?: To::excerpt($s['content']);
    // Return the first part!
    return trim(explode('<!-- cut -->', $s['content'])[0]);


How to enable the manual post excerpt:

title: Post Title
description: Post description.
author: Taufik Nurrohman
type: Markdown

This paragraph is going to be the post excerpt.

<!-- cut -->

Rest of the post content goes here.

To show the manual post excerpt in your shield:

<?php echo $page->excerpt; ?>

Info: The plugin version of this snippet is now available as excerpt plugin.