Skip to content

Instantly share code, notes, and snippets.

@hissy
Created July 1, 2020 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissy/1191bf7ca811607afc5dfbacd753a078 to your computer and use it in GitHub Desktop.
Save hissy/1191bf7ca811607afc5dfbacd753a078 to your computer and use it in GitHub Desktop.
[concrete5] Example: Customize SEO meta tags for express entry detail
<?php
namespace Application\Block\ExpressEntryDetail;
use Concrete\Core\Html\Service\Seo;
use Concrete\Core\Url\SeoCanonical;
class Controller extends \Concrete\Block\ExpressEntryDetail\Controller
{
public function action_view_express_entity($exEntryID = null)
{
$entry = $this->entityManager->find('Concrete\Core\Entity\Express\Entry', $exEntryID);
if (is_object($entry)) {
$entity = $this->entityManager->find('Concrete\Core\Entity\Express\Entity', $this->exEntityID);
if ($entry->getEntity()->getID() == $entity->getID()) {
/** @var Seo $seo */
$seo = $this->app->make('helper/seo');
// Get the value of meta_title attribute of the entry
$seo->setCustomTitle($entry->getMetaTitle());
// Get the value of meta_description attribute of the entry
$this->addHeaderItem('<meta name="description" content="' . h($entry->getMetaDescription()) . '">');
/** @var SeoCanonical $canonical */
$canonical = $this->app->make(SeoCanonical::class);
$canonical->setPathArguments(['view_express_entity', $exEntryID]);
$this->set('entry', $entry);
$this->view();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment