How do I add SEO Metadata to a page?
You can use the \Aero\Marketing\Facades\SearchOptimization facade to add SEO Metadata to a page.
See below an example of how we do it for \Aero\Store\Http\Responses\Homepage & Aero\Store\Http\Responses\InformationPage by adding the Aero\Store\Http\Responses\Steps\Page\AttachMetaData step:
class AttachMetaData
{
public function handle(\Aero\Responses\ResponseBuilder $builder, \Closure $next)
{
/** @var $page \Aero\Content\Models\Page */
$page = $builder->page;
if (! $page->key) {
\Aero\Marketing\Facades\SearchOptimization::setTitle($page->name);
}
if ($page->seo) {
\Aero\Marketing\Facades\SearchOptimization::setCanonical($page->getCanonical());
if (! empty($page->seo->page_title)) {
\Aero\Marketing\Facades\SearchOptimization::setTitle($page->seo->page_title, false);
}
if ($page->seo->noindex) {
\Aero\Marketing\Facades\SearchOptimization::setNoIndex();
}
if ($page->seo->nofollow) {
\Aero\Marketing\Facades\SearchOptimization::setNoFollow();
}
}
\Aero\Marketing\Facades\SearchOptimization::setDescription($page->getMetaDescription());
\Aero\Marketing\Facades\OpenGraph::withPage($page);
return $next($builder);
}
}
Methods
| Method |
Description |
setTitle($title, $appendDefault = true) |
Sets the page title, optionally appending the configured default title postfix. |
setDescription(string $description) |
Sets the page meta description. |
setCanonical($canonical) |
Sets the canonical URL for the page. |
setAmpHtml(string $url) |
Sets the AMP HTML URL. |
addAlternativeLanguage(string $lang, string $url) |
Adds an alternate-language URL with its hreflang language code. |
addAlternativeLanguages(array $languages) |
Adds multiple alternate-language URLs. |
setNoIndex(bool $index = true) |
Enables or disables the noindex robots directive. |
setNoFollow(bool $follow = true) |
Enables or disables the nofollow robots directive. |
setRobotContent(?string $content) |
Sets custom robots meta content. |
setNext(LengthAwarePaginator $listings) |
Sets the next-page URL for paginated content. |
setPrev(LengthAwarePaginator $listings) |
Sets the previous-page URL for paginated content. |