Installation:
composer require atoolo/seo-bundle
Add the bundle to config/bundles.php:
return [
// ...
Atoolo\SeoBundle\AtooloSeoBundle::class => ['all' => true],
];
Configuration: Publish the default config:
php bin/console config:dump-reference AtooloSeoBundle
Or override in config/packages/atoolo_seo.yaml:
atoolo_seo:
sitemap:
enabled: true
max_urls_per_sitemap: 2000 # Default from 1.1.0
routes: ['app.homepage', 'app.blog_post']
First Use Case:
Generate a sitemap by visiting /sitemap.xml (route: atoolo_seo.sitemap). The bundle auto-discovers routes based on your routes.yaml or annotations.
Sitemap Generation:
atoolo_seo.yaml under sitemap.routes. Supports named routes (Symfony’s app.* syntax).
sitemap:
routes:
- 'app.homepage'
- { route: 'app.blog_post', priority: 0.8 }
Atoolo\SeoBundle\Provider\UrlProviderInterface to fetch URLs dynamically (e.g., from a database).
class CustomUrlProvider implements UrlProviderInterface {
public function getUrls(): array {
return [
['url' => '/dynamic-page', 'priority' => 0.9],
];
}
}
Register as a service:
services:
App\Provider\CustomUrlProvider:
tags: ['atoolo_seo.url_provider']
URL Rewriting:
atoolo/rewrite-bundle integration to canonicalize URLs. Configure in atoolo_rewrite.yaml:
rewrites:
- { pattern: '/old-url', to: '/new-url' }
Meta Tags:
Twig to inject meta tags via the atoolo_seo Twig extension:
{% seo_meta title: 'Page Title' description: 'Meta description' %}
Atoolo\SeoBundle\Twig\SeoExtension or create a custom Twig function.HttpCache or VarCache:
framework:
http_cache:
sitemap_cache: true
phpstan (level 9) to catch type-related issues early.UrlProviderInterface in PHPUnit:
$this->container->set('atoolo_seo.url_provider.custom', $mockProvider);
Route Discovery:
atoolo_seo.yaml or implement a custom UrlProvider.php bin/console debug:router to verify route names.XML Limits:
max_urls_per_sitemap (default: 2000). Monitor memory usage for large sites.Twig Extension:
seo_meta Twig function overwrites existing meta tags. Use sparingly or wrap in conditional blocks:
{% if not meta_tags_defined %}
{% seo_meta title: 'Fallback Title' %}
{% endif %}
Dependency Conflicts:
atoolo/resource-bundle, atoolo/search-bundle, and atoolo/rewrite-bundle. Ensure these are installed and configured.composer why-not atoolo/seo-bundle to debug missing dependencies./sitemap.xml or debug the UrlProvider:
$provider = $container->get('atoolo_seo.url_provider.main');
var_dump($provider->getUrls());
APP_DEBUG=true) to log sitemap generation warnings.Custom Sitemap Index:
Override the Atoolo\SeoBundle\Controller\SitemapController to modify the sitemap index structure (e.g., add lastmod or changefreq).
Event Listeners:
Subscribe to atoolo.seo.sitemap.generate to inject URLs dynamically:
use Symfony\Component\EventDispatcher\GenericEvent;
$dispatcher->addListener('atoolo.seo.sitemap.generate', function (GenericEvent $event) {
$event->getArgument('urls')->add(['url' => '/dynamic-url']);
});
Configuration Overrides:
Use environment-specific configs (e.g., config/packages/dev/atoolo_seo.yaml) to toggle features:
# config/packages/dev/atoolo_seo.yaml
atoolo_seo:
sitemap:
enabled: false # Disable in dev
How can I help you explore Laravel packages today?