Created
July 1, 2020 09:58
-
-
Save hissy/1191bf7ca811607afc5dfbacd753a078 to your computer and use it in GitHub Desktop.
[concrete5] Example: Customize SEO meta tags for express entry detail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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