A simple PHP based blogging platform.

Custom Functions

Pure Blog loads /content/functions.php automatically if it exists. Use it to define your own PHP helper functions without modifying the Pure Blog core files.

How it works

Create /content/functions.php in your site. It is included after all core functions are loaded, so you have full access to everything in the core.

<?php

function my_helper(): string
{
    return 'Hello!';
}

Your functions are then available everywhere — in layout templates, page templates, and custom includes.

Use cases

Example: star rating

/content/functions.php

<?php

function render_star_rating(string $rating): string
{
    $parts = explode('/', $rating);
    $score = (int) ($parts[0] ?? 0);
    $max = (int) ($parts[1] ?? 5);
    $stars = '';
    for ($i = 1; $i <= $max; $i++) {
        $stars .= $i <= $score ? '★' : '☆';
    }
    return '<span class="star-rating" aria-label="' . e($rating) . '">' . $stars . '</span>';
}

/content/layouts/book.php

<p><b>Rating:</b> <?= render_star_rating($post['rating']) ?></p>

Notes

docs

⬅ Previous post
Custom Post Layouts

Next post ➡
Core Functions Reference