Snippet · Mecha CMS

Code snippet collection for developers.

Dynamic Site Description/Slogan

Author: Taufik Nurrohman · 343 Views

Tweet

Automatically change the site slogan based on the current page description.

Hook::set('route.enter', function() use($site, $url) {
    $path = PAGE . DS . ($site->is === 'pages' ? $url->path : Path::D($url->path));
    if ($path = File::exist([
        $path . '.page',
        $path . '.archive'
    ])) {
        $description = Page::open($path)->get('description', $site->description);
        $description = t($description, '<p>', '</p>');
        Config::set('description', $description);
    }
});

0 Comments

No comments yet.