Snippet · Mecha CMS

Code snippet collection for developers.

Automatic Paragraph

Author: Taufik Nurrohman · 459 Views

Tweet

Wrap description data with paragraph tags if it doesn’t have paragraph tags.

Hook::set('page.description', function($content) {
    // Wrap description data with paragraph tag(s) if needed
    if ($content && strpos($content, '</p>') === false) {
        return '<p>' . str_replace(["\n\n", "\n"], ['</p><p>', '<br>'], trim(n($content))) . '</p>';
    }
    return $content;
});

0 Comments

No comments yet.