Installation:
composer require austral/seo-bundle
Ensure Austral\SeoBundle\AustralSeoBundle is registered in config/bundles.php.
Configuration: Publish the default config:
php bin/console austral:seo:install
Update config/packages/austral_seo.yaml (e.g., enable/disable features like url_parameter or redirection).
First Use Case:
SeoMetadata trait in your controller or entity:
use Austral\SeoBundle\Traits\SeoMetadata;
class PageController
{
use SeoMetadata;
public function show(Page $page): Response
{
$this->setSeoMetadata($page); // Auto-fills OpenGraph, Twitter, and canonical tags
return $this->render('page/show.html.twig', ['page' => $page]);
}
}
use Austral\SeoBundle\Annotation\UrlParameterObject;
#[UrlParameterObject]
class BlogPost
{
// ...
}
Entity-Driven SEO:
@UrlParameterObject on entities to auto-generate SEO URLs (e.g., /blog/{slug}).getSeoTitle(), getSeoDescription(), etc., in your entity or DTO:
class Product
{
public function getSeoTitle(): string
{
return "Buy {$this->name} - Best Price";
}
}
URL Parameter Management:
php bin/console austral:seo:url-parameter:list
php bin/console austral:seo:url-parameter:create BlogPost slug
$this->get('austral.seo.url_parameter.management')->create(
'BlogPost',
'slug',
'blog/{slug}'
);
Redirection Handling:
redirection.enabled: true in config. The bundle auto-creates redirects when UrlParameter paths change (e.g., /old-path → /new-path).Multi-Domain Support:
austral_seo.yaml:
domains:
- 'example.com'
- 'blog.example.com'
getDomain() in entities to return the correct base URL.Twig Integration:
{{ seo_metadata(page) }}
{% block seo_custom %}
<meta property="article:published_time" content="{{ page.publishedAt|date('c') }}">
{% endblock %}
symfony/ux-turbo for SPA-like SEO (e.g., hydrate metadata via API calls).prePersist/preUpdate to update SEO fields:
$entity->setSeoDescription($this->generateDescription($entity));
SeoMetadata in API controllers to return SEO headers (e.g., X-Robots-Tag).Annotation Cache:
@UrlParameterObject, clear the cache:
php bin/console cache:clear
php bin/console debug:container austral.seo.url_parameter.listener
Redirection Conflicts:
redirection:
enabled: false
Austral\SeoBundle\Entity\Redirection.Multi-Domain Pitfalls:
domain field in entities is populated. Use a listener if missing:
$entity->setDomain(request()->getHost());
URL Parameter Validation:
UrlParameter paths manually if using custom routes:
$this->get('validator')->validate(
$urlParameter,
new Assert\Regex('/^\/[a-z0-9\-]+\/[a-z0-9\-]+$/')
);
$this->get('logger')->debug('SEO Metadata', [
'title' => $this->getSeoTitle(),
'description' => $this->getSeoDescription(),
]);
<meta property="og:title">).Custom Metadata Providers:
Override the SeoMetadataProvider service to add logic:
austral_seo.seo_metadata_provider: App\Service\CustomSeoProvider
class CustomSeoProvider extends SeoMetadataProvider
{
public function getSeoTitle($entity): string
{
return "[Custom] {$entity->getName()}";
}
}
Event Listeners:
Extend SEO logic via events (e.g., seo.metadata.pre_build):
$event->setTitle($event->getTitle() . " | Custom Suffix");
Dynamic URL Parameters:
Use the UrlParameterObject interface to add custom logic:
class CustomUrlParameter implements UrlParameterObject
{
public function getUrlParameterPath(): string
{
return '/custom/{id}-{slug}';
}
}
composer remove austral/entity-seo-bundle
seo.metadata.auto_generate if manually managing metadata to avoid overhead.austral:seo:metadata:update command to regenerate metadata for all entities:
php bin/console austral:seo:metadata:update Product
SeoMetadata to support multiple languages:
public function getSeoTitle(string $locale = 'en'): string
{
return $this->translator->trans($this->title, [], $locale);
}
SeoMetadata trait in PHPUnit:
$this->entity->method('getSeoTitle')->willReturn('Test Title');
How can I help you explore Laravel packages today?